回答
所以,這就是我隨同。我希望代碼是自我解釋的。
有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. 刪除圖像中的所有特定顏色(顏色範圍)?
- 2. 使用MATLAB分離圖像顏色
- 3. 使用as3更改圖像特定部分的顏色
- 4. Jgrapht邊緣顏色
- 5. Python PIL基於其顏色刪除圖像的部分
- 6. 圖像上邊緣和底部邊緣的命名約定
- 7. 從圖像C中刪除白色邊緣#
- 8. ggplot:刪除色帶邊緣的線
- 9. 改變圖像特定部分的顏色onclick按鈕
- 10. Bash:在圖像的特定部分填充顏色
- 11. 平滑顏色圖圖像中的邊緣
- 12. 刪除顏色表的一部分
- 13. 邊界在Matlab中刪除圖像
- 14. 如何使用MATLAB將圖像的一部分的顏色更改爲同一圖像的另一部分
- 15. 向自定義邊緣添加顏色
- 16. 邊緣去除(在Matlab)
- 17. 用另一種顏色替換圖像中的特定顏色
- 18. python - opencv morphologyEx刪除特定顏色
- 19. 刪除Matlab繪圖邊界
- 20. 樹狀圖邊緣(分支)顏色匹配提示(葉)顏色(猿包)
- 21. 更改圖像部分的顏色
- 22. 圖像的填充(顏色)部分
- 23. Python:在NetworkX中着色特定邊緣
- 24. 從圖像中刪除選定的顏色(灰度圖形)
- 25. 如何刪除一些Mathematica圖形上的白色邊緣
- 26. 更改圖像中的特定顏色
- 27. 從svg圖像中刪除像素化邊緣
- 28. 如何在MATLAB中使用'fill'功能時更改邊緣線的顏色?
- 29. 用OpenCV刪除圖像的部分
- 30. 使用jQuery刪除所有元素的背景顏色/圖像
但是,事情是由紫色各地surounded。爲什麼只有那一個? –
抱歉給您帶來不便。我必須從圖像中去除所有紫色環境,而不僅僅是紅色標記區域。我希望你明白。 –