灰度级的扩展与压缩

这里使用matlab实现laplacian图像锐化的一个例子:

I = imread('2.jpg');
I_g = rgb2gray(I);
imtool(I_g)
% 使用laplacian进行图像锐化,该过程会产生负值,因此需要使用double类型
w = fspecial('laplacian',0);
I_g_d = double(I_g);
g = imfilter(I_g_d,w,'replicate');
I_g_g = I_g_d-g;
imtool(I_g_g,[]);

原图像:

使用laplacian锐化图像的过程中,图像灰度级发生了变化。后续为了编程的方便,我们需要将数据恢复到0-255之间,这里不能使用mapminmax(参考:matlab函数mapminmax不适用与于图像处理中的灰度级的扩展与压缩

方法1:

y = 255*(I_g_g-min(min(I_g_g)))/(max(max(I_g_g))-min(min(I_g_g)));
y=uint8(y);
imtool(y,[])

输出图像:


方法2:

y1=mat2gray(I_g_g); % 将数据压缩到0-1,数据类型仍为double
y1 = im2uint8(y1); % 将数据恢复到0-255,数据类型变为uint8
imtool(y1);

方法3:使用im2double与im2uint8

扫描二维码关注公众号,回复: 49709 查看本文章
I = imread('2.jpg');
I_g = rgb2gray(I);
imtool(I_g)
% 使用laplacian进行图像锐化,该过程会产生负值,因此需要使用double类型
w = fspecial('laplacian',0);
I_g_d = im2double(I_g);
g = imfilter(I_g_d,w,'replicate');
I_g_g = I_g_d-g;
imtool(I_g_g,[]);

y1 = im2uint8(y1);
imtool(y1);

猜你喜欢

转载自blog.csdn.net/superjunenaruto/article/details/80052327