Answers.Body: <p>From how it looks, the most reliable method to try out is using Hough transform.</p>
  <p>The Hough transform can be used to detect e.g. lines and circles in images (depending on which variant you are using; in this case it would amount to a combination of variants for both lines and circles obviously).</p>
  <p>So, given some input image, the Hough transform tells you what the line/circle parameters are that have created a line in the input image. For example, given a line, it would tell you the intersection with the <span class="math-container">$y$</span>-axis and the <span class="math-container">$slope$</span> of the line detected in the image.
  Then, you could use these parameter information to reconstruct lines and circles detected in the image.</p>
  <p>The last remaining problem to be solved then is to check where a detected line starts and stops (since this is not obvious from line parameters like <span class="math-container">$m$</span> (=<span class="math-container">$slope$</span>) and <span class="math-container">$b$</span> (=intersection with <span class="math-container">$y$</span>-axis) in the equation <span class="math-container">$y = mx+b$</span> describing some line).</p>
  <p>But for that, you could &quot;walk&quot; along a line in the image space and check where the line is present or not. Then, you can draw line segments in the reconstruction image when the corresponding elements are also present in the original image.</p>
  <p>The problem with (C)NNs would be that they are sensitive to rotation and scale etc. You could of course take a tremendously large number of filters to account for shapes of different rotation and scale, but that would increase the demand for labeled training data again (which could of course be automatically be generated a priori in this simple case).</p>
  <p>Anyway, I'd suggest checking out Hough transform. To get some feeling for it, there are lots of libraries available implementing it for <a href="https://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_imgproc/py_houghlines/py_houghlines.html" rel="nofollow noreferrer">Python</a> or <a href="https://www.mathworks.com/help/images/ref/hough.html" rel="nofollow noreferrer">MatLab</a>, for example.</p>
  <p>For further information, check out <a href="https://en.wikipedia.org/wiki/Hough_transform" rel="nofollow noreferrer">Wikipedia</a> or <a href="https://www.youtube.com/watch?v=hYcugbbf9ug&amp;feature=youtu.be&amp;t=756" rel="nofollow noreferrer">YouTube</a>.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-07-11T00:06:06.513Z
Answers.LastActivityDate: 2020-07-11T00:06:06.513Z
Answers.UserDisplayName: Daniel B.
Body: <p>Given a hand-drawn shape, I'd like to generate the corresponding symmetrical polished shapes such as circle, rectangle, triangle,  trapezoid, square, parallelogram, etc.</p>
  <p><a href="https://www.lynda.com/OneNote-tutorials/Convert-hand-drawn-shapes-polished-symmetrical-shapes/574673/603787-4.html" rel="nofollow noreferrer">A short video demonstration</a></p>
  <p>Here below we can see a parallelogram, trapezoid, triangle and a circle.
  I was wondering how can I transform it into symmetrical polished shapes?</p>
  <p><a href="https://i.sstatic.net/ccI5C.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/ccI5C.png" alt="enter image description here" /></a></p>
  <p>At first, I tried a simple approach with traditional computer vision algorithms, with OpenCV (no neural networks were involved), by counting the number of corners, but it failed miserably, since there are many edge cases within a user's doodler.</p>
  <p>So, I was thinking to delve into CNN specifically U-Net for segmentation.</p>
  <p>Can somebody please give me some suggestions on how to approach this kind of problem? I'd like to read some relevant articles and code about this subject for getting a better grasp of this kind of problem.</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-07-09T05:42:06.287Z
Comments.Text: Depending on how you want to do this problem it could be really easy. Do you just want the ability to have simple shapes drawn? Because if you only care about a small sample of shapes, you can make a super simple classifier network that would have no trouble getting very high accuracy, then if it detects a square, just return an image of a square. But again, this depends on the complexity of the task. Will there be multiple shapes? Does the output need to resemble the dimensions of the input?
Comments.UserDisplayName: Recessive
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-07-09T06:55:19.520Z
Comments.Text: @Recessive thank you for your questions, yes I would like to generate those polished shapes, But the actual position is important for me, and moreover the shapes can reside inside other shapes, therefore it's not only a classification problem. I have updated the question with more details. and have uploaded an image.
Comments.UserDisplayName: JammingThebBits
Tags: <convolutional-neural-networks><object-recognition><image-segmentation><u-net>
Title: How to quickly change hand-drawn shapes to symmetrical polished shapes?
UserDisplayName: JammingThebBits
ThreadText: # How to quickly change hand-drawn shapes to symmetrical polished shapes?
  
  (Asked by: username_0 on 2020-07-09)
  
  Given a hand-drawn shape, I'd like to generate the corresponding symmetrical polished shapes such as circle, rectangle, triangle, trapezoid, square, parallelogram, etc.
  
  [A short video demonstration](https://www.lynda.com/OneNote-tutorials/Convert-hand-drawn-shapes-polished-symmetrical-shapes/574673/603787-4.html)
  
  Here below we can see a parallelogram, trapezoid, triangle and a circle.
  I was wondering how can I transform it into symmetrical polished shapes?
  
  [![enter image description here](https://i.sstatic.net/ccI5C.png)](https://i.sstatic.net/ccI5C.png)
  
  At first, I tried a simple approach with traditional computer vision algorithms, with OpenCV (no neural networks were involved), by counting the number of corners, but it failed miserably, since there are many edge cases within a user's doodler.
  
  So, I was thinking to delve into CNN specifically U-Net for segmentation.
  
  Can somebody please give me some suggestions on how to approach this kind of problem? I'd like to read some relevant articles and code about this subject for getting a better grasp of this kind of problem.
  
  **Tags:** convolutional-neural-networks, object-recognition, image-segmentation, u-net
  
  > **Comments:**
  > **username_1**: Depending on how you want to do this problem it could be really easy. Do you just want the ability to have simple shapes drawn? Because if you only care about a small sample of shapes, you can make a super simple classifier network that would have no trouble getting very high accuracy, then if it detects a square, just return an image of a square. But again, this depends on the complexity of the task. Will there be multiple shapes? Does the output need to resemble the dimensions of the input?  
  > **username_0**: @username_1 thank you for your questions, yes I would like to generate those polished shapes, But the actual position is important for me, and moreover the shapes can reside inside other shapes, therefore it's not only a classification problem. I have updated the question with more details. and have uploaded an image.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2020-07-11. Score: 1
  
  From how it looks, the most reliable method to try out is using Hough transform.
  
  The Hough transform can be used to detect e.g. lines and circles in images (depending on which variant you are using; in this case it would amount to a combination of variants for both lines and circles obviously).
  
  So, given some input image, the Hough transform tells you what the line/circle parameters are that have created a line in the input image. For example, given a line, it would tell you the intersection with the $y$-axis and the $slope$ of the line detected in the image.
  Then, you could use these parameter information to reconstruct lines and circles detected in the image.
  
  The last remaining problem to be solved then is to check where a detected line starts and stops (since this is not obvious from line parameters like $m$ (=$slope$) and $b$ (=intersection with $y$-axis) in the equation $y = mx+b$ describing some line).
  
  But for that, you could "walk" along a line in the image space and check where the line is present or not. Then, you can draw line segments in the reconstruction image when the corresponding elements are also present in the original image.
  
  The problem with (C)NNs would be that they are sensitive to rotation and scale etc. You could of course take a tremendously large number of filters to account for shapes of different rotation and scale, but that would increase the demand for labeled training data again (which could of course be automatically be generated a priori in this simple case).
  
  Anyway, I'd suggest checking out Hough transform. To get some feeling for it, there are lots of libraries available implementing it for [Python](https://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_imgproc/py_houghlines/py_houghlines.html) or [MatLab](https://www.mathworks.com/help/images/ref/hough.html), for example.
  
  For further information, check out [Wikipedia](https://en.wikipedia.org/wiki/Hough_transform) or [YouTube](https://www.youtube.com/watch?v=hYcugbbf9ug&feature=youtu.be&t=756).
  
  
  ---
  
  