How to have different threshold for different images?
31 views (last 30 days)
Show older comments
I am doing edge detection of microcell images directly taken form microscope. One image has 25 microwells containing the cells. I am cropping the 25 automatically and trying to do edge detection. The code is working. However, because of the threshold the edge detection (outilne formed on the cell spheroid) is not perfect, missing the actual outer edge of the spehroid.
Radius of diamond/ length of line does make a difference but Threshold is the main factor.
I treid adpatthresh and graythresh but they hardly made any difference.
It will be very good if anyone can guide me on how to have variable threshold that suits different images for proper edge detection.
Thanks
0 Comments
Accepted Answer
C B
on 7 Dec 2022
In general, the threshold used in edge detection algorithms plays a critical role in determining the quality of the detected edges. A high threshold will result in only the strongest edges being detected, while a low threshold will detect more edges but may also include more noise and false edges.
In your specific case, it sounds like the threshold you are using is not providing good results. One way to address this issue would be to try using a different thresholding method, such as Otsu's method, which can automatically determine an appropriate threshold based on the image intensity histogram.
In MATLAB, you can use the graythresh function with the 'Otsu' method to apply Otsu's thresholding to an image. Here is an example of how you can use this function to determine an appropriate threshold for edge detection:
% Load the image
I = imread('microcell_image.png');
% Use Otsu's method to determine the threshold
threshold = graythresh(I, 'Otsu');
% Use the threshold to detect edges in the image
edges = edge(I, 'Canny', threshold);
Alternatively, you can try using the adaptivethreshold function to apply adaptive thresholding to the image, which can be more effective at detecting edges in images with varying contrast. Here is an example of how you can use this function to perform adaptive thresholding on an image:
% Load the image
I = imread('microcell_image.png');
% Use adaptive thresholding to detect edges in the image
edges = edge(I, 'Canny', adaptivethreshold(I));
Using either of these approaches should provide better results than the thresholding method you are currently using, and may help to improve the quality of the edge detection in your microcell images.
More Answers (1)
Image Analyst
on 7 Dec 2022
You can use the interactive thresholding utility in my File Exchange:
It may be possible to have the threshold automatically determined. I don't know because you forgot to attach any images.
One major obstacle to using a global threshold is that the images have not been background corrected. All lenses have shading so your image will be darker at the corners and edges than at the middle. Unless you correct for that, you won't have a good binary image.
And you may or may not need edge detection. Beginners often do it unnecessarily. Just because you can see edges in the image does not mean edge detection is a necessary step in the segmentation algorithm. Again, I won't know until I see your pictures.
I'm attaching a few demos that may interest you.
If you have any more questions, then attach your data and code to read it in with the paperclip icon after you read this:
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!