回答
所以,这就是我随同。我希望代码是自我解释的。
有2个值需要玩。其中之一是imdilate
中的数字。那将会定义“边界有多大”。当然这取决于你。
另一个是HSV颜色分割的值。在HSV中,H是颜色,而紫色在250-335范围内。问题是蓝色与紫色非常相似,紫色和蓝色之间的界限非常模糊。我在代码中使用了250作为下限,但是您可能需要修改它。
如果您有任何问题,请询问。
% The image is indexed image. Else convert.
[img,c]=imread('https://i.imgur.com/dxkJSi0.png');
% Get part with color
bwimg=img~=0;
% get only the biggest part
lblimg=bwlabel(bwimg,4);
stat = regionprops(lblimg,'Centroid','Area','PixelIdxList');
[maxValue,index] = max([stat.Area]);
todelete=1:size(stat,1);
todelete(index)=[];
for ii=todelete
bwimg(stat(ii).PixelIdxList)=0;
end
%update image with without "noise"
img(~bwimg)=0;
% get the contour of the image (thanks @rayryeng)
er = imerode(bwimg, strel('square', 3));
out = imsubtract(bwimg, er);
% we will increase the boundary so we pick a larger region
% Here you need your input. it depedns how much you dilate the image, the
% part of the of the image that will be considered boudnary will increase.
boundary=imdilate(out,strel('square', 10));
% now lets see withc colors are purple. For that we get HSV space. Shades
% of purple are aruond 265~335 H
hsvc=rgb2hsv(c);
purple=find(hsvc(:,1)>250/360&hsvc(:,1)<335/360);
% Get purple in the whole image
purpleimg=zeros(size(img));
for ii=1:size(purple)
purpleimg(img==purple(ii))=purple(ii);
end
% get locations of purple in the boudnary
purpbound=purpleimg.*boundary~=0;
% delete them from the original image
imgNOpurple=img;
imgNOpurple(purpbound)=0;
% plot results
figure(1)
subplot(221)
imshow(purpleimg,c)
title('purple in the image')
subplot(222)
imshow(purpleimg.*boundary,c);
title('purple boundary')
subplot(223)
imshow(img,c)
title('original image')
subplot(224)
imshow(imgNOpurple,c);
title('Image without purple boundary')
非常感谢。这非常有帮助。 –
你能帮我解决另一个问题吗?我有100多个这种类型的图像。我想以* .tif格式将所有最终图像(没有紫色边界的图像)保存在我的计算机文件夹中。我怎样才能做到这一点?谢谢 –
@jonsnowknowsnothing如果你有另一个问题要问另一个问题;)。因此,这个答案在这里已经有好几次了,所以googleingWill会帮助你! –
- 1. MATLAB streamribbon边缘颜色
- 2. 删除图像中的所有特定颜色(颜色范围)?
- 3. 使用MATLAB分离图像颜色
- 4. 使用as3更改图像特定部分的颜色
- 5. Jgrapht边缘颜色
- 6. 从位图图像的特定部分更改颜色
- 7. Python PIL基于其颜色删除图像的部分
- 8. 图像上边缘和底部边缘的命名约定
- 9. 从图像C中删除白色边缘#
- 10. 删除图片边缘
- 11. 更改边缘的颜色
- 12. ggplot:删除色带边缘的线
- 13. 改变图像特定部分的颜色onclick按钮
- 14. Bash:在图像的特定部分填充颜色
- 15. 平滑颜色图图像中的边缘
- 16. 删除颜色表的一部分
- 17. 如何使用MATLAB将图像的一部分的颜色更改为同一图像的另一部分
- 18. 边界在Matlab中删除图像
- 19. HTML 5画布:从线条边缘删除颜色渐变
- 20. R igraph边缘颜色
- 21. 颜色边缘检测+ opencv
- 22. 边缘填充颜色
- 23. 向自定义边缘添加颜色
- 24. 使用PHP的Neo4j图中的颜色边缘
- 25. 边缘去除(在Matlab)
- 26. Matlab图像边缘调整/细化
- 27. 图像对齐第二个图像的边缘div部分
- 28. 删除特定td的底部边框
- 29. 用另一种颜色替换图像中的特定颜色
- 30. python - opencv morphologyEx删除特定颜色
但是,事情是由紫色各地surounded。为什么只有那一个? –
抱歉给您带来不便。我必须从图像中去除所有紫色环境,而不仅仅是红色标记区域。我希望你明白。 –