[英]MATLAB: RGB to white and black image
我不知道任何特殊功能,但是解決方案非常簡單:
I = imread('sLUp2.png'); %Read source image.
%Initialize all destination pixels to 1
J = ones(size(I,1), size(I,2));
%Set to zero pixels which are gray in I (where Red==Green and Red==Blue).
J((I(:,:,1) == I(:,:,2)) & (I(:,:,1) == I(:,:,3))) = 0;
在以上解決方案中,所有具有R = G = B的源灰度像素均被視為灰度。
例如:黑色像素(0,0,0),白色像素(255,255,255)和(x,x,x)被視為灰色...
如果您只想查找單個普通灰度級(而不是所有“灰度”像素),則可以執行以下操作(某些操作):
R = I(:, :, 1); %Red color plane.
Gray = R((I(:,:,1) == I(:,:,2)) & (I(:,:,1) == I(:,:,3))); %All values in which R=G=B.
H = imhist(Gray, 256); %Collect histogram of Gray.
common_gray = find(H == max(H)) - 1; %Find the most common gray value in histogram.
%Now, set only common_gray pixels to zero in destination image J.
J = ones(size(I,1), size(I,2));
J(R == common_gray) = 0;
在圖像中,常見的灰度級(“灰度點”)等於128 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.