【#文档大全网# 导语】以下是®文档大全网的小编为您整理的《Matlab实现对图像抖动算法》,欢迎阅读!
%********************************Task 1***********************************
% For a 8-bit gray image (lena.bmp)
% Use a dithering matrix (4*4), generate the dithered image.
%*************************************************************************
%function defined
function []=dither1()
%import the 8-bit gray image (lena.bmp)
I=imread('image/lena.bmp');
[I_length,I_width]=size(I);
%Define the 4*4 matrix
D = [0,8,2,10; 12,4,14,6; 3,11,1,9; 15,7,13,5];
%Output matrix
O=zeros(4*I_length,4*I_width);
%Map the image (0~255) to a new scope (0~16) and dither
divide=256/17;
tmp_I=I./(divide);
for x = 1:I_length
for y = 1:I_width
for p = 1:4
for q = 1:4
if tmp_I(x,y)>= D(p,q)
O(4 *(x-1) + p,4 *(y-1) + q) = 1;
else
O(4 *(x-1) + p,4 *(y-1) + q) = 0;
end
end
end
end
end
%show the result
subplot(121),imshow(I),title('8-bit gray lena.bmp');
subplot(122),imshow(O),title('dithered image');
本文来源:https://www.wddqxz.cn/1bb6d2ec5bf5f61fb7360b4c2e3f5727a5e924d6.html