📄 dither.m
字号:
function imout=dither(arg1,arg2,arg3,arg4,arg5,arg6)
%DITHER Convert image using dithering.
% X = DITHER(RGB,MAP) creates an indexed image approximation of
% the RGB image in the array RGB by dithering the colors in
% colormap MAP.
%
% X = DITHER(RGB,MAP,Qm,Qe) creates an indexed image from RGB,
% specifying the parameters Qm and Qe. Qm specifies the number
% of quantization bits to use along each color axis for the
% inverse color map, and Qe specifies the number of
% quantization bits to use for the color space error
% calculations. If Qe < Qm, dithering cannot be performed and
% an undithered indexed image is returned in X. If you omit
% these parameters, DITHER uses the default values Qm = 5,
% Qe = 8.
%
% BW = DITHER(I) converts the intensity image in the matrix I
% to the binary image BW by dithering.
%
% Class Support
% -------------
% The input image (RGB or I) can be of class double or
% uint8. All other input arguments must be of class double. The
% output image (X or BW) is of class uint8 if it is a binary
% image or if it an indexed image with 256 or fewer colors;
% otherwise its class is double.
%
% See also RGB2IND.
% Joseph M. Winograd 7-93
% Copyright 1993-1998 The MathWorks, Inc. All Rights Reserved.
% $Revision: 5.11 $ $Date: 1997/11/24 15:34:34 $
% References:
% R. W. Floyd and L. Steinberg, "An Adaptive Algorithm for
% Spatial Gray Scale," International Symposium Digest of Technical
% Papers, Society for Information Displays, 36. 1975.
% Spencer W. Thomas, "Efficient Inverse Color Map Computation",
% Graphics Gems II, (ed. James Arvo), Academic Press: Boston.
% 1991. (includes source code)
if nargin < 1,
error('Need input arguments');
end
threeD = (ndims(arg1)==3); % Determine if input includes a 3-D array
if threeD,
if nargin < 4
arg4 = 8; % DEFAULT: If this is changed, modify the other occurrence
% for NOT(threeD).
end
if nargin < 3
arg3 = 5; % DEFAULT: See note above.
end
if nargin==1
error('Wrong number of input parameters.');
else
if (~isa(arg1,'uint8'))
arg1 = uint8(round(255*arg1));
end
im = ditherc(arg1(:,:,1),arg1(:,:,2),arg1(:,:,3),arg2,arg3,arg4);
end
map = arg2;
else % R, G, and B are passed in as separate variables.
error( nargchk( 1, 6, nargin ) );
if nargin < 6
arg6 = 8; % DEFAULT
end
if nargin < 5
arg5 = 5; % DEFAULT
end
if nargin==1
if (~isa(arg1,'uint8'))
arg1 = uint8(round(255*arg1));
end
im = im2bw(ditherc(arg1,arg1,arg1,gray(2),arg5,arg6),gray(2));
elseif nargin==2 | nargin==3,
error('Wrong number of input parameters.');
else
if (~isa(arg1,'uint8'))
arg1 = uint8(round(255*arg1));
end
if (~isa(arg2,'uint8'))
arg2 = uint8(round(255*arg2));
end
if (~isa(arg3,'uint8'))
arg3 = uint8(round(255*arg3));
end
im = ditherc(arg1,arg2,arg3,arg4,arg5,arg6);
map = arg4;
end
end
if nargout==0,
if (nargin==1 & ~threeD), imshow(im,2), else, imshow(im,map), end
return
end
imout = im;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -