Object-counting in image processing.
10 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Kangkan
am 20 Okt. 2013
Kommentiert: Image Analyst
am 28 Okt. 2020
I am doing a project on object-counting from images. For that, I have taken two images- one is the background containing no objects and the other containing some objects(toy-cars) over it.
Background Image:

------------------------------------------------------------
Image with objects over it:

The difference-image between the two images is taken and converted to black-and-white using a threshold value. The problem is that some of the pixels inside the objects match with the background and so these pixels are also getting subtracted completely and as a result, some black pixels are occurring inside the objects as you can see from the b/w image below and so the objects are getting divided into parts.

I need each object to occur as one object so that we get the exact no of objects. Can someone please help me regarding this.
The code I have used is below:
I = imread('Snap5.png');
J = imread('bg1.png');
K = imabsdiff(I,J);
th = graythresh(K);
L = im2bw(K,th);
[LabeledIm,ConnectedObj] = bwlabel(L,4);
coloredLabels = label2rgb (LabeledIm, 'hsv', 'k', 'shuffle');
ConnectedObj
figure,
subplot(221), imshow(K), title('Difference'),
subplot(222), imshow(L), title('Thresholded BW'),
subplot(223), imshow(coloredLabels), title('Color-labeled Objects');
9 Kommentare
Image Analyst
am 28 Okt. 2020
Kangkan hasn't been here in 7 years, but you can sure give it try. Just copy, paste, and change image filename, and run.
Akzeptierte Antwort
Image Analyst
am 20 Okt. 2013
Replace these two lines:
L = im2bw(K,th);
[LabeledIm,ConnectedObj] = bwlabel(L,4);
with these
binaryImage = im2bw(K,th);
binaryImage = imclose(binaryImage, true(5)); % Close gaps and connect nearby blobs.
binaryImage = bwconvhull(binaryImage); % Make shapes convex and fill holes.
[LabeledIm,ConnectedObj] = bwlabel(binaryImage,4);
1 Kommentar
Image Analyst
am 20 Okt. 2013
Also see my Image Segmentation tutorial in my File Exchange http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862
Weitere Antworten (1)
Fasih Chishti
am 29 Jan. 2015
Hello! I'm doing project on Image counting... How could i count the objects from any picture? Thanks
0 Kommentare
Siehe auch
Kategorien
Mehr zu Image Processing Toolbox finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
