本文介绍了使用matlab的彩色半色调的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法使用带有误差扩散方法的matlab制作彩色半色调图像,原始输入图像被分解为三种颜色(青色,品红色和黄色),然后每种颜色将转换为半色调图像,如。

I have trouble to make color halftone image using matlab with error diffusion method which is the original input image is decomposed to three colors (cyan, magenta, and yellow) and then each color will be transformed into halftone image like this picture.

我一直在搜索,我发现灰度图像的jarvis误差扩散方法:

I've been searching and i found jarvis error diffusion method for grayscale 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));

但它不适用于彩色图像。我该怎么办?

But it didn't work for color image. What should i do?

推荐答案

您是否尝试过使用

然而,一般情况下,半色调是一次完成一个颜色平面。在屏幕半色调的情况下,通常每种颜色都有一个屏幕。但是,在您的情况下,您似乎想要一个FM屏幕,在这种情况下,您可以为每个颜色平面使用相同的算法。

In general however, halftoning is done one color plane at a time. In the case of screen halftoning, you would generally have a screen per color. However, in your case it seems like you want an FM screen, in which case you may use the same algorithm per color plane.

假设您的jarvisHalftone例程适用于灰度图像,然后您可以使用以下内容创建颜色半色调方法:

Assuming your jarvisHalftone routine works for a grayscale image, then you can create a color halftoning method using using something like:

function outImg = jarvisColorHalftone(inImg)
[N,M,P] = size(inImg);
outImg = logical(zeros([N,M,P]));
for p = 1:P
  outImg(:,:,p) = jarvisHalftone(inImg(:,:,p));

这篇关于使用matlab的彩色半色调的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-16 05:44