如何使用MATLAB代码为半色调着色?
我首先使用jarvis黑白半色调然后修改它的颜色半色调。
我的方法: -
function outImg = jarvisColorHalftone(inImg)
[N,M,P] = size(inImg);
outImg = logical(zeros([N,M,P]));
for p = 1:P
outImg(:,:,p) = jarvisHalftone(inImg(:,:,p));
end
outImg;
上述功能无效。
// jarvisHalftone function for grayscale to black and white image
function outImg = jarvisHalftone(inImg)
inImg = double(inImg);
[M,N] = size(inImg);
T = 127.5;
y = inImg;
error = 0;
y= [127.5*ones(M,2) y 127.5*ones(M,2) ; 127.5*ones(2,N+4)];
z = y;
for rows = 1:M
for cols = 3:N+2
z(rows,cols) =255*(y(rows,cols)>=T);
error = -z(rows,cols) + y(rows,cols);
y(rows,cols+2) = 5/48 * error + y(rows,cols+2);
y(rows,cols+1) = 7/48 * error + y(rows,cols+1);
y(rows+1,cols+2) = 3/48 * error + y(rows+1,cols+2);
y(rows+1,cols+1) = 5/48 * error + y(rows+1,cols+1);
y(rows+1,cols+0) = 7/48 * error + y(rows+1,cols+0);
y(rows+1,cols-1) = 5/48 * error + y(rows+1,cols-1);
y(rows+1,cols-2) = 3/48 * error + y(rows+1,cols-2);
y(rows+2,cols+2) = 1/48 * error + y(rows+2,cols+2);
y(rows+2,cols+1) = 3/48 * error + y(rows+2,cols+1);
y(rows+2,cols+0) = 5/48 * error + y(rows+2,cols+0);
y(rows+2,cols-1) = 3/48 * error + y(rows+2,cols-1);
y(rows+2,cols-2) = 1/48 * error + y(rows+2,cols-2);
end
end
outImg = z(1:M,3:N+2);
outImg = im2bw(uint8(outImg));