回答
所以,這就是我隨同。我希望代碼是自我解釋的。
有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。爲什麼只有那一個? –
抱歉給您帶來不便。我必須從圖像中去除所有紫色環境,而不僅僅是紅色標記區域。我希望你明白。 –