collect all same coins in each figure

2 次查看(过去 30 天)
Dear all;
I want to collect all same value coins in each figure. For example, all 1 cent coin in 1 figure, all 5 cent coin in 1 figure. How can I do that?
Really appreciate for your help
clc;
close all;
clear;
I = imread("money.png");
Ig = rgb2gray(I);
imshow(Ig);
Ib = imbinarize(Ig,'global');
imshow(Ib);
se = strel('disk',2);
Ih = imerode(Ib,se);
Ih = Ib - Ih;
imshow (Ih);
If = imfill(Ih,'holes');
label = bwlabel(If);
max(max(label));
im1 = (label ==1);
figure;
imshow(im1)
for i = 1:max(max(label));
[row, col] = find(label ==i);
len = max(row)-min(row)+2;
breath = max(col)-min(col) +2;
target = uint8(zeros([len breath]));
sy = min(col) - 1;
sx = min(row) - 1;
for j = 1:size(row,1);
x = row(j,1) - sx;
y = col(j,1) - sy;
target(x,y) = I(row(j,1),col(j,1));
end
mytitle = strcat('Object Number:',num2str(j));
figure;
imshow(target);
end

回答(1 个)

Image Analyst
Image Analyst 2023-9-7
This is just what my tutorial does. See my Image Segmentation Tutorial in my File Exchange:
It's a generic, general purpose demo of how to threshold an image to find blobs, and then measure things about the blobs, and extract certain blobs based on their areas or diameters, like dimes or nickels only.

类别

Help CenterFile Exchange 中查找有关 Get Started with Image Processing Toolbox 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by