【发布时间】:2017-02-28 16:01:51
【问题描述】:
如这张图,如何用matlab代码将其分割成不同的部分,然后填充颜色呢?另外,如何在第二个代码中设置渐变色???
图片分割代码如下:
clc
rgb=imread('sample1.bmp');
bw=im2bw(rgb2gray(rgb),.8);
bw=medfilt2(bw);
planes=bwareaopen(bw,800);
D=mat2gray(bwdist(imcomplement(planes)));
stats=regionprops(D>.8,'Centroid');
planes_centroid=cat(1,stats.Centroid);
planes_mask=false(size(bw));
planes_mask(sub2ind(size(bw),round(planes_centroid(:,2)),...
round(planes_centroid(:,1))))=1;
M=imimposemin(imcomplement(D),planes_mask);
L=watershed(M);
r=L & planes;
stats=regionprops(r,'BoundingBox','Centroid')
bb=cat(1,stats.BoundingBox);
c=cat(1,stats.Centroid);
figure,imshow(planes)
hold on
for i=1:length(stats)
rectangle('Position',bb(i,:),'EdgeColor','b')
plot(c(i,1),c(i,2),'r*')
text(c(i,1)-5,c(i,2)-10,num2str(i))
end
%second code
clc;clf;close all;clear all;
color=cell(4,1);
for i=1:4
input=imread(['heartspline2_4_',num2str(i)],'bmp');
figure,imshow(input);
BW=im2bw(input,graythresh(input));
[B,L]=bwboundaries(BW,'noholes');
for k=1:length(B)
boundary=B{k};
ind=size(boundary(:,2));
plot(boundary(:,2),boundary(:,1),'k','LineWidth',2);
hold on;
axis off;
if (k==1)
patch(boundary(:,2),boundary(:,1),'w');
else
patch(boundary(:,2),boundary(:,1),???);
end
end
saveas(gca,['y_','heartspline2_4_',num2str(i)],'bmp')
close(gcf)
end
【问题讨论】:
-
你可以把图片转换成svg(很多免费的在线工具),然后很容易改变路径的颜色,看这个例子:stackoverflow.com/questions/20211890/…
-
欢迎来到 StackOverflow!你应该自己研究和尝试。然后,如果您对代码有问题,请来询问您的具体问题,同时分享minimal, complete, and verifiable example。
-
我需要在matlab中处理。
标签: matlab image-processing computer-vision image-segmentation