|
楼主 |
发表于 2012-8-29 21:18:39
|
显示全部楼层
- function varargout = im_bitcut(impath,n)
- % IM_BITCUT 图像位图切割函数
- % 数字图像分解为位平面,每一位平面为一二值图像
- % | 0 f(x,y) < 2^n
- % g(x,y) = |
- % | 255 f(x,y) >= 2^n
- % n为位平面序号
- % $Author: lskyp $Date: 2009.08.22
- image1 = imread(impath);
- if ndims(image1) == 3
- image1 = rgb2gray(image1);
- end
- image1 = double(image1);
- [h,w] = size(image1);
- imfinal = zeros(h,w);
- for p = 1:h
- for q = 1:w
- tempgray = floor(image1(p,q)/(2^n));
- if rem(tempgray,2) == 1
- imfinal(p,q) = 255;
- end
- end
- end
- imfinal = im2uint8(mat2gray(imfinal));
- if nargout == 0
- imshow(imfinal)
- title(['位平面' num2str(n)]);
- else
- varargout = imfinal;
- end
- 实验如下:
- 复制内容到剪贴板
- 代码:
-
- for k = 7:-1:0
- subplot(2,4,8 - k)
- im_bitcut('cameraman.tif',k)
- end
复制代码 |
|