如何替換具有某個RGB範圍的像素,而不僅僅是如question中所示的特定值,例如R範圍爲140-150的像素,G範圍從50-55和B的範圍從61-70,另一個單值如(150,57,80)。如果有人可以請指教。用另一種顏色替換圖像中的某個顏色範圍Matlab
0
A
回答
4
這也是我在之前發佈的其他問題中提供的答案的修改。您只需更改logical
掩模計算,以便我們搜索一系列紅色,綠色和藍色值。
這樣:
red = A(:,:,1); green = A(:,:,2); blue = A(:,:,3);
%// Change here
mred = red >= 140 & red <= 150;
mgreen = green >= 50 & green <= 55;
mblue = blue >= 61 & blue <= 70;
%// Back to before
final_mask = mred & mgreen & mblue;
red(final_mask) = 150; green(final_mask) = 57; blue(final_mask) = 80;
out = cat(3, red, green, blue);
2
原來你需要做一些修改,找到合適的匹配像素位置。這裏的實現 -
%// Initialize vectors for the lower and upper limits for finding suitable
%// pixels to be replaced
lower_lim = [140,50,61]
upper_lim = [150,55,70]
%// Initialize vector for new pixels tuplet
newval = [150,57,80]
%// Reshape the input array to a 2D array, so that each column would
%// represent one pixel color information.
B = reshape(permute(A,[3 1 2]),3,[])
%// Find out which columns fall within those ranges with `bsxfun(@ge` and `bsxfun(@le`
matches = all(bsxfun(@ge,B,lower_lim(:)) & bsxfun(@le,B,upper_lim(:)),1)
%// Replace all those columns with the replicated versions of oldval
B(:,matches) = repmat(newval(:),1,sum(matches))
%// Reshape the 2D array back to the same size as input array
out = reshape(permute(B,[3 2 1]),size(A))
相關問題
- 1. 用另一種顏色替換圖像中的某種顏色Matlab
- 2. 用另一種顏色替換圖像中的特定顏色
- 3. 用CSS3中的圖像中的另一種顏色替換顏色
- 4. 用另一種顏色替換uiimage中的顏色
- 5. 使用PHP替換圖像中的另一種顏色
- 6. 在NSImage中替換另一種顏色
- 7. 將某些像素RGB顏色到另一種顏色
- 8. 背景顏色50%一種顏色和50%另一種顏色
- 9. 用圖像/精靈中的另一個替換特定顏色
- 10. 從一種特定顏色到另一種顏色的研究生matlab繪圖
- 11. 刪除圖像中的所有特定顏色(顏色範圍)?
- 12. matlab中顏色條的顏色的自定義範圍?
- 13. 確定一種顏色「圖像中單個顏色的多少」
- 14. 用另一種顏色更改所有像素的顏色
- 15. 用matlab中的顏色浮點範圍定製的顏色映射圖
- 16. 這種顏色在哪個X11顏色範圍內
- 17. 在圖像中搜索顏色範圍
- 18. 用Lockbits替換圖像的顏色
- 19. 如何替換圖像中的顏色?
- 20. 需要更快的方法來替換基於另一種顏色的圖像中的顏色
- 21. dc.js製作兩種顏色之間的顏色範圍
- 22. gnuplot熱圖顏色範圍
- 23. 將ShapeDrawable中的單色(黑色)替換爲Android中的另一種顏色
- 24. 將自動文本顏色替換爲選中的某種顯式顏色
- 25. 如何將一種顏色替換爲eps文件的每個對象中的另一種顏色?
- 26. 從一種顏色到另一種顏色的插值
- 27. 使用CSS給一個黑色的圖標另一種顏色
- 28. 直接從高亮顏色切換顏色到另一種顏色
- 29. 顏色範圍Python
- 30. 如何將某些顏色分類爲顏色範圍?
另外,請註明如果他們是由一個單一的連音被取代? – Divakar 2015-02-11 04:44:50
什麼是單連音符? – Tak 2015-02-11 04:45:54
就像它們被單像素彩色信息所取代一樣,比如'(150,57,80)'? – Divakar 2015-02-11 04:46:38