matlab练习程序(Floyd–Steinberg dithering)

close all;
clear all;
clc;
img=imread('pic.bmp');
imshow(img);
[m n]=size(img);

re=zeros(m,n);
tmp=zeros(m+2,n+2);
tmp(2:m+1,2:n+1)=img;

for i=2:m+1
for j=2:n+1
if tmp(i,j)<128
re(i-1,j-1)=0;
err=tmp(i,j);
else
re(i-1,j-1)=255;
err=tmp(i,j)-255;
end
tmp(i,j+1)=tmp(i,j+1)+7/16*err;
tmp(i+1,j-1)=tmp(i+1,j-1)+3/16*err;
tmp(i+1,j)=tmp(i+1,j)+5/16*err;
tmp(i+1,j+1)=tmp(i+1,j+1)+1/16*err;
end
end

figure,imshow(re);

图片福利:

matlab练习程序(Floyd–Steinberg dithering)_第1张图片                                   

matlab练习程序(Floyd–Steinberg dithering)_第2张图片

转载于:https://www.cnblogs.com/tiandsp/archive/2012/04/03/2431275.html

你可能感兴趣的:(matlab练习程序(Floyd–Steinberg dithering))