我的输入图像是
输出图像是
预期的输出是这样的
可以看出,一些类似椭圆的结构与矩形合并。此外,我无法将每个标签分开以获得椭圆使用的算法是分水岭
clear; close all;
I = imread('Sub.png');
I = rgb2gray(I);
figure; imshow(I)
I2 = imtophat(I, strel('square', 45));
figure; imshow(I2)
% Alpha=.047;
% h = fspecial('motion', 10, 5);
% w=gausswin(I2,Alpha) % you'll have to play with N and alpha
% I2 = imfilter(I2,h,'same','symmetric'); % something like these options
level = .047;
BW = im2bw(I2,level);
D = -bwdist(~BW,'chessboard');
D(~BW) = -Inf;
L = watershed(D);
imshow(label2rgb(L,'jet','w'))
最终开启代码:
ImageSource=imread('cameraman.tif');
ImTmp=ImageSource
ImResidue = zeros(size(ImageSource));
ImIndicator= zeros(size(ImageSource));
ImValues= zeros(size(ImageSource));
For size= 1 : N
se = strel('square',N);
ImOp = imopen(ImageSource,se);
ImDiff=imabsdiff(ImOp,ImTmp)
if ImResidue < ImDiff then
ImResidue = ImDiff
ImIndicator = size
ImValues = ImOp
end
ImTmp=ImOp
end