Home > Blockchain >  What I can used to detect shape similar to circles in python?
What I can used to detect shape similar to circles in python?

Time:09-02

enter image description here

This is the image and my aim is to detect only the middle nuclei of cell

Code for detecting nuclei shape (similar to circle) from below image

import cv2
import numpy as np
planets = cv2.imread('52.BMP')
gray_img    =   cv2.cvtColor(planets,   cv2.COLOR_BGR2GRAY)
img = cv2.medianBlur(gray_img,  5)
cimg = cv2.cvtColor(img,cv2.COLOR_GRAY2BGR)
circles = cv2.HoughCircles(img,cv2.HOUGH_GRADIENT,1,120,param1=100,param2=30,minRadius=0,maxRadius=0)
circles=circles.astype(float)
circles = np.uint16(np.around(circles))
for i in circles[0,:]:
                cv2.circle(planets,(i[0],i[1]),i[2],(0,255,0),6)
                cv2.circle(planets,(i[0],i[1]),2,(0,0,255),3)
cv2.imshow("HoughCirlces",  planets)
cv2.waitKey()
cv2.destroyAllWindows()

I'm getting this error everytime

AttributeError: 'NoneType' object has no attribute 'rint'

The above exception was the direct cause of the following exception:

    Traceback (most recent call last):
      File "C:\Users\ABHISHEK\PycharmProjects\cervical_project1\hsv.py", line 33, in <module>
        circles = np.uint64(np.around(circles))
      File "<__array_function__ internals>", line 180, in around
      File "C:\python310\lib\site-packages\numpy\core\fromnumeric.py", line 3348, in around
        return _wrapfunc(a, 'round', decimals=decimals, out=out)
      File "C:\python310\lib\site-packages\numpy\core\fromnumeric.py", line 54, in _wrapfunc
        return _wrapit(obj, method, *args, **kwds)
      File "C:\python310\lib\site-packages\numpy\core\fromnumeric.py", line 43, in _wrapit
        result = getattr(asarray(obj), method)(*args, **kwds)
    TypeError: loop of ufunc does not support argument 0 of type NoneType which has no callable rint method

Is there any other way to detect only the nuclei of cell?

CodePudding user response:

For large images hough transformation based searches can become slow. Since you have a contrast difference between cell and nucleus you could transform your image into a grayscale image (maybe even using only one color channel if the contrast is better in a single one) and then applying blob detection. That also allows for filtering the nuclei according to certain shapes or sizes.

Edit: Your submitted traceback says that the error comes from line 33 of hsv.py. As Christoph Rackwitz already stated, the provided code is missing this part or the error message doesn't correspond to your code. Anyway in your line

circles = cv2.HoughCircles(img,cv2.HOUGH_GRADIENT,1,120,param1=100,param2=30,minRadius=0,maxRadius=0)

you are setting minRadius and maxRadius to 0. Probably because of this no circle is found and np.around tries to act on None which leads to your final error message.

CodePudding user response:

Binarization of the green component gives a usable result. Use contouring, and filter out the unwanted blobs. (You could rely on the isoperimetric ratio.)

enter image description here

Unfortunately, this method will be very sensitive to the color mixture.

  • Related