Answers.Body: <p>Yes, this is possible.</p>
  
  <p>There is actually a pretty <strong>easy way that doesn't even require machine learning</strong> and can be <strong>implemented with a small amount of code</strong>. You just use a framework for image processing (e.g. <a href="https://pypi.python.org/pypi/PIL" rel="noreferrer">PIL</a> for Python), find the marks by going over your image with an appropriate filter and use the implemented crop function, that the framework hopefully provides (or write i yourself with 2 nested for loops copying the area). Your filter will react strongest in the areas of your image that look like the mark you defined. This could actually be implemented like a single layer conv+RELU layer in a CNN (see <a href="https://adeshpande3.github.io/adeshpande3.github.io/A-Beginner%27s-Guide-To-Understanding-Convolutional-Neural-Networks/" rel="noreferrer">this introduction</a> for details about conv and RELU layers).</p>
  
  <p>Because you are asking explicitly about machine learning, I will also give you the hard version to solve this problem using a full CNN to identify the bounding box. Once you have found the bounding box, the actual cropping can be done like in the example above and is not part of the CNN. You could call it post processing if you like.</p>
  
  <p>The technique you are looking for is called <a href="https://leonardoaraujosantos.gitbooks.io/artificial-inteligence/content/object_localization_and_detection.html" rel="noreferrer">Object Localization and Detection</a>. The linked article should tell you all the details you need. You basically build and train your CNN to localize and identify interesting objects in your image. The <strong>easy way</strong> is to train your CNN to <strong>identify the 4 marks individually</strong> and return the coordinates of the 4 areas with the highest likelihood to contain your marks. You calculate the center of those 4 individual points and feed it to your cropping function. The <strong>hard way</strong> is to <strong>find the smallest bounding box containing all 4 marks</strong>. This is a much harder problem, because the neural network needs to learn that it should ignore everything except those 4 marks during detection, although they will be a small portion of the bounding box. It can be done, but looking for the 4 marks individually would be much easier.</p>
  
  <p>Which approach is best for you? Depends on your goal. If you need a <strong>robust and efficient algorithm</strong> for this problem, <strong>forget about ML</strong> and <strong>implement it with the straight forward approach</strong> I described first. No need for fancy learning CNNs. You can implement this with a few dozen lines of code.</p>
  
  <p>If this is a research or training project to study ML, take my second approach. The easy and the hard way are both fine, the hard one obviously more challenging for your CNN. If you are new to CNN, I recommend following <a href="https://www.youtube.com/playlist?list=PL3FW7Lu3i5JvHM8ljYj-zLfQRF3EO8sYv" rel="noreferrer">this Stanford Course</a>. It teaches you all you need for your project in 25 to 30 hours (excluding homework).</p>
  
  <hr>
  
  <p>Edit: Concerning your question, how do you add your own marks. I would simply do it using with the same framework you use for cropping. Your program needs some kind of image manipulation capabilities and this will allow pixel manipulation as well (at least the framework <a href="https://pypi.python.org/pypi/PIL" rel="noreferrer">PIL</a> which I suggested has this capability). Just draw your mark using this method. You can also copy a sample mark with a transparent background using a tool like Gimp manually, if you prefer that.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-09-02T16:37:36.090Z
Answers.LastActivityDate: 2017-09-02T16:42:49.740Z
Answers.LastEditDate: 2017-09-02T16:42:49.740Z
Answers.UserDisplayName: Demento
Answers.Body: <p>If you are so sure that ML is the way to go ahead, then try following.</p>
  
  <ol>
  <li><p><a href="https://github.com/tensorflow/models/tree/master/research/object_detection" rel="nofollow noreferrer">Tensorflow code for object detection</a> </p></li>
  <li><p><a href="https://pjreddie.com/darknet/yolo/" rel="nofollow noreferrer">YOLO</a>
  This is especially for real time object detection. </p></li>
  </ol>
  
  <p>You can train these model for your object in question &amp; see the results.There are some other localization models that you can try. </p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-11-18T13:06:11.213Z
Answers.LastActivityDate: 2018-11-18T13:06:11.213Z
Answers.UserDisplayName: Ruchit Dalwadi
Body: <p>Is there a way to train AI to find aspecific line or symbol in a image and crop it?</p>
  
  <p>OpenCV scripts finds a face and crops it: how can I add my annotations? </p>
  
  <p>Lest say I have a image like this:</p>
  
  <p><code>
   +------+
   |  *  *|
   |      |
   |  *  *|
   |      |
   +------+
  </code></p>
  
  <p>I want it to find the * and crop it.</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-09-03T21:49:02.713Z
Comments.Text: I very much like simple problems like these, and have no doubt ML could be effectively applied to this.  Which it wouldn't be the most efficient solution to the stated problem, I could see how it would be very useful when extended to similar, non-trivial problems. Welcome to AI!
Comments.UserDisplayName: DukeZhou
Tags: <machine-learning><algorithm><image-recognition>
Title: Cropping image using ML?
UserDisplayName: E P
ThreadText: # Cropping image using ML?
  
  (Asked by: username_0 on 2017-09-02)
  
  Is there a way to train AI to find aspecific line or symbol in a image and crop it?
  
  OpenCV scripts finds a face and crops it: how can I add my annotations?
  
  Lest say I have a image like this:
  
  `+------+
  | * *|
  | |
  | * *|
  | |
  +------+`
  
  I want it to find the \* and crop it.
  
  **Tags:** machine-learning, algorithm, image-recognition
  > **Comments:**
  > **username_1**: I very much like simple problems like these, and have no doubt ML could be effectively applied to this.  Which it wouldn't be the most efficient solution to the stated problem, I could see how it would be very useful when extended to similar, non-trivial problems. Welcome to AI!  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_2 on 2017-09-02. Score: 6
  
  Yes, this is possible.
  
  There is actually a pretty **easy way that doesn't even require machine learning** and can be **implemented with a small amount of code**. You just use a framework for image processing (e.g. [PIL](https://pypi.python.org/pypi/PIL) for Python), find the marks by going over your image with an appropriate filter and use the implemented crop function, that the framework hopefully provides (or write i yourself with 2 nested for loops copying the area). Your filter will react strongest in the areas of your image that look like the mark you defined. This could actually be implemented like a single layer conv+RELU layer in a CNN (see [this introduction](https://adeshpande3.github.io/adeshpande3.github.io/A-Beginner%27s-Guide-To-Understanding-Convolutional-Neural-Networks/) for details about conv and RELU layers).
  
  Because you are asking explicitly about machine learning, I will also give you the hard version to solve this problem using a full CNN to identify the bounding box. Once you have found the bounding box, the actual cropping can be done like in the example above and is not part of the CNN. You could call it post processing if you like.
  
  The technique you are looking for is called [Object Localization and Detection](https://leonardoaraujosantos.gitbooks.io/artificial-inteligence/content/object_localization_and_detection.html). The linked article should tell you all the details you need. You basically build and train your CNN to localize and identify interesting objects in your image. The **easy way** is to train your CNN to **identify the 4 marks individually** and return the coordinates of the 4 areas with the highest likelihood to contain your marks. You calculate the center of those 4 individual points and feed it to your cropping function. The **hard way** is to **find the smallest bounding box containing all 4 marks**. This is a much harder problem, because the neural network needs to learn that it should ignore everything except those 4 marks during detection, although they will be a small portion of the bounding box. It can be done, but looking for the 4 marks individually would be much easier.
  
  Which approach is best for you? Depends on your goal. If you need a **robust and efficient algorithm** for this problem, **forget about ML** and **implement it with the straight forward approach** I described first. No need for fancy learning CNNs. You can implement this with a few dozen lines of code.
  
  If this is a research or training project to study ML, take my second approach. The easy and the hard way are both fine, the hard one obviously more challenging for your CNN. If you are new to CNN, I recommend following [this Stanford Course](https://www.youtube.com/playlist?list=PL3FW7Lu3i5JvHM8ljYj-zLfQRF3EO8sYv). It teaches you all you need for your project in 25 to 30 hours (excluding homework).
  
  ---
  
  Edit: Concerning your question, how do you add your own marks. I would simply do it using with the same framework you use for cropping. Your program needs some kind of image manipulation capabilities and this will allow pixel manipulation as well (at least the framework [PIL](https://pypi.python.org/pypi/PIL) which I suggested has this capability). Just draw your mark using this method. You can also copy a sample mark with a transparent background using a tool like Gimp manually, if you prefer that.
  
  
  ---
  
  ### Answer by username_3 on 2018-11-18. Score: 0
  
  If you are so sure that ML is the way to go ahead, then try following.
  
  1. [Tensorflow code for object detection](https://github.com/tensorflow/models/tree/master/research/object_detection)
  2. [YOLO](https://pjreddie.com/darknet/yolo/)
     This is especially for real time object detection.
  
  You can train these model for your object in question & see the results.There are some other localization models that you can try.
  
  
  ---
  
  