Get points coordinates in correspondance to ellipse axes

username: Roua_Rouatbi
cooked: <p>I have a couple of objects that have points inside of them. I fitted an ellipse around them and want to get the coordinates of the points in a normalized way since the ellipses have different shapes and rotations</p>
<p>The original images are as such:<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/5/0/503c913dade68486ec5e1ab2f9a3091c37660b92.png" data-download-href="https://discuss.pytorch.org/uploads/default/503c913dade68486ec5e1ab2f9a3091c37660b92" title="image"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/5/0/503c913dade68486ec5e1ab2f9a3091c37660b92_2_690x188.png" alt="image" data-base62-sha1="brNXG9ABy1ZdQ6bvhhR1I9SurT4" width="690" height="188" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/5/0/503c913dade68486ec5e1ab2f9a3091c37660b92_2_690x188.png, https://discuss.pytorch.org/uploads/default/original/3X/5/0/503c913dade68486ec5e1ab2f9a3091c37660b92.png 1.5x, https://discuss.pytorch.org/uploads/default/original/3X/5/0/503c913dade68486ec5e1ab2f9a3091c37660b92.png 2x" data-dominant-color="929C93"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">image</span><span class="informations">856×234 59.1 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>
<p>I got to this point but don’t know how to make the axes of the ellipse as my axes:<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/d/5/d59f5749f9fd5b63e1513e47d48adab5cdaa49c4.png" data-download-href="https://discuss.pytorch.org/uploads/default/d59f5749f9fd5b63e1513e47d48adab5cdaa49c4" title="image"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/d/5/d59f5749f9fd5b63e1513e47d48adab5cdaa49c4_2_346x500.png" alt="image" data-base62-sha1="utN5qYZsCiTaA9A1viW4Py4gklu" width="346" height="500" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/d/5/d59f5749f9fd5b63e1513e47d48adab5cdaa49c4_2_346x500.png, https://discuss.pytorch.org/uploads/default/original/3X/d/5/d59f5749f9fd5b63e1513e47d48adab5cdaa49c4.png 1.5x, https://discuss.pytorch.org/uploads/default/original/3X/d/5/d59f5749f9fd5b63e1513e47d48adab5cdaa49c4.png 2x" data-dominant-color="030D04"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">image</span><span class="informations">367×529 34.7 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>
<p>I first fitted the ellipse:</p>
<pre><code class="lang-auto"># find largest contour
mask_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
               
ret, thresh = cv2.threshold(mask_gray, 0, 255, cv2.THRESH_BINARY)

contours, hierarchy = cv2.findContours(thresh, cv2.RETR_TREE,
                                                                           cv2.CHAIN_APPROX_SIMPLE)
cnt=[item for sublist in contours for item in sublist]
cnt=np.asarray(cnt)
ellipse = cv2.fitEllipse(cnt)
                    
(xc,yc),(d1,d2),angle = ellipse
</code></pre>
<p>I then detected the points and drew them with the cv2.circle function then drew the ellipse<br>
I also drew the axis this way:</p>
<pre><code class="lang-auto">rmajor = max(d1,d2)/2
if angle &gt; 90:
     angle = angle - 90
else:
      angle = angle + 90
xtop = xc + math.cos(math.radians(angle))*rmajor
ytop = yc + math.sin(math.radians(angle))*rmajor
xbot = xc + math.cos(math.radians(angle+180))*rmajor
ybot = yc + math.sin(math.radians(angle+180))*rmajor
cv2.line(result, (int(xtop),int(ytop)), (int(xbot),int(ybot)), (0, 0, 255), 1)
</code></pre>
<p>I then rotated the image with:</p>
<pre><code class="lang-auto">result = ndimage.rotate(result,angle) 
</code></pre>
<p>with the angle being the angle of the ellipse so that the axes are kind of the same for all ellipses since I want the coordinates to be normalized for all images</p>