title: Difficulty in detected ellipses in image
body: <p>I am trying to detect ellipses in some images.
  After some functions I got this edges map:</p>
  
  <p><img src="https://i.stack.imgur.com/UNVX0.png" alt="edge map"></p>
  
  <p>I tried using Hough transform to detect ellipses, but this transform has very high complexity, so my computer didn't finish running the transform command even after 5 hours(!).</p>
  
  <p>I also tried doing connected components and got this:</p>
  
  <p><img src="https://i.stack.imgur.com/HZB6U.png" alt="connected components"></p>
  
  <p>In last case I also tried continue and binarized the image.</p>
  
  <p>In all cases I am stuck in these steps, and have no idea how continue from here.</p>
  
  <p>My mission is detect tomatoes in the image. I am approaching this by trying to detect circles and ellipses and find the radius (or average radius in ellipses case) for each one.</p>
  
  <p>edited:</p>
  
  <p>I add my code for the first method (the result is edge map from above):</p>
  
  <pre><code>img = cv2.imread(r'../images/assorted_tomatoes.jpg')
  
  gray_img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
  
  imgAfterLight=lightreduce(img)
  imgAfterGamma=gamma_correctiom(imgAfterLight,0.8)
  
  th2 = 255 - cv2.adaptiveThreshold(imgAfterGamma,255,cv2.ADAPTIVE_THRESH_GAUSSIAN_C,cv2.THRESH_BINARY,5,3)
  median2 = cv2.medianBlur(th2,3)
  </code></pre>
  
  <p>where median2 is the result of shown above in edge map</p>
  
  <p>and the code for connected components:</p>
  
  <pre><code>import scipy
  from scipy import ndimage
  import matplotlib.pyplot as plt
  import cv2
  import numpy as np
  
  fname=r'../images/assorted_tomatoes.jpg'
  blur_radius = 1.0
  threshold = 50
  
  img = scipy.misc.imread(fname) # gray-scale image
  gray_img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
  print(img.shape)
  
  # smooth the image (to remove small objects)
  imgf = ndimage.gaussian_filter(gray_img, blur_radius)
  threshold = 80
  
  # find connected components
  labeled, nr_objects = ndimage.label(imgf &gt; threshold) 
  </code></pre>
  
  <p>where labeled is the result above</p>
  
  <p>another edit:</p>
  
  <p>this is the input image:</p>
  
  <p><a href="https://i.stack.imgur.com/JrAf8.jpg" rel="nofollow noreferrer">Input</a></p>
  
  <p>The problem is that after edge detection, there are a lot of unnecessary edges in sub regions that disturbing for make smooth edge map</p>