Isolating specific dots in an image.

Hello, I'm trying to get my image to the point where only the dots inside the black squares remain.
So far, all I've done with this code is use inmextendedmin on the original grayscale image, and then masked it ontop of the grayscale image to produce this result.
figure(1);
imshow(grayImage);
mask = imextendedmin(grayImage,2);
figure(2);
imshow(mask);
figure(3);
imshowpair(grayImage,mask,'blend');
Before, I had been trying to use watershedding, dividing the background, and a lot of other neat tricks to try and single out the black dots, but it seems that this simple bit of code alone gets me half way to what I want (As each black square has a dot already in it, all i want are those dots). Is there a way to get rid of everything else in this image besides the gray dots inside the black dots?
The problem I often had with watershedding and whatnot is I needed a variable threshold, as well as watershedding was rather time and processes intensive, so I'm trying to find more efficient ways of doing it.

1 个评论

Notice also how there is a lot of different levels of darkness in the background, wondering if that too may be an issue.

请先登录,再进行评论。

 采纳的回答

im=imread('https://www.mathworks.com/matlabcentral/answers/uploaded_files/122320/2steps%20from%20perfection.PNG');
im=max(im,[],3);
bw_bkg=imfill(im<=50,'holes');
bw=im>50 & bw_bkg;
figure, imshow(bw)

更多回答(1 个)

Kimo Kalip
Kimo Kalip 2018-6-22
Oh man, thats perfect, thanks!

13 个评论

So I tried it out this morning, and it seems that the difference in background levels has made my attempt fail... Think theres any way around it?
On the left:
>> bw_bkg = imfill(im<=50, 'holes');
>> imshow(bw_bkg);
On the right:
>> bw = C > 50 & bw_bkg;
>> figure(5);
>> imshow(bw);
Is that "almost worked.png" your input image or output image?
You marked this as Accepted. So is it working or not? I tried to find https://www.mathworks.com/matlabcentral/answers/uploaded_files/122320/2steps%20from%20perfection.PNG but you seem to have taken it down for some reason. Do you still want help or not? If so, please post your input image.
Kimo, that example was specific to the image you posted. To get it to work for other similar images, you will have to adjust the intensity threshold for the background (set to 50 in the previous example).
Oh, I understand, thanks! The intention was to find some sort of way to sidestep the thresholding, but it seems theres no reliable way around it.
Also, I'm sorry I had to take down the original photo, apparently it was "too close" to the pre-processed image that I got in trouble for uploading it. Would an image created in paint representing the same sort of idea suffice enough as an example for other people looking at this later to better understand what the intention was?
Thanks again!
Or you can cut-out a representative region of the original image and post that
Does this work?
Also, what had happened with the later photo (The one with the comparisons), I had essentially zoomed out and noticed the threshold wasn't quite uniform throughout the rest of the image - something I've been struggling with a lot lately (And the original reason for attempting this fix). I just can't find a reliable pattern or any way to automate the threshold part mathematically - maybe I should find a way to extract an average light level of pixels and then go from there?
I would include a larger portion of the region containing the "dots" you want to segment in the sample image
This a bit better? The trick here was just separating the dots in the black blobs rather than all the other white dots, think its enough for a general idea?
Yeah, that should work. Now what is your question?
Oh, you answered it, don't worry - thanks! I had hoped to use this method in order to get around using thresholds to isolate those black blobs (As thresholds need to be tweaked on a per-picture basis, so I was trying to find some robust way of automating the isolation without needing the human touch). Work in progress, but I don't think i can get around thresholding.
For your type of image data, you can try to automate threshold selection as follows:
(1) Initialize threshold (e.g., thr=10)
(2) Apply threshold to image and count the number of connected components (representing the "wells" in which the white dots are embedded) above some a priori defined area
(3) Increment threshold: thr_new <-- thr + 1
(4) Repeat (2) using thr_new and compare number of connected components obtained with thr, if the number of "wells" decreases, accept thr as best value of intensity threshold and terminate search, otherwise set thr <-- thr_new and go to step (2)
I hadn't thought of that, its actually a really good idea - thanks! Where does it stop though? Wouldn't I want to keep going until all of the wells disappear? But by the same token, I imagine I'd start losing dots I actually want to keep before I got rid of all the large wells, no?
Thanks again for all the help so far!

请先登录,再进行评论。

类别

产品

版本

R2017a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by