伽马变换的效果和对数变化的效果类似。伽马变换的基本形式为:
对于不同的gamma值,s与r的关系曲线如下图所示:
gamma值小于1,可以看到处理结果扩展了低灰度值;gamma值大于1,可以看到处理结果扩展了高灰度值;
- 首先处理一张整体偏暗的图片,即需要扩展灰度级。
下列代码中,为何要使用mat2gray等函数,可参考我的另一篇博客中的代码,里面有详细解释。
处理结果如下:% 读入图像 img_1 = imread('Fig0308(a)(fractured_spine).tif'); % 伽马变换,伽马值为0.6 img_2 = im2uint8(mat2gray(power(double(img_1), 0.6))); % 伽马变换,伽马值为0.4 img_3 = im2uint8(mat2gray(power(double(img_1), 0.4))); % 伽马变换,伽马值为0.3 img_4 = im2uint8(mat2gray(power(double(img_1), 0.3))); % 显示图像 subplot(141), imshow(img_1); subplot(142), imshow(img_2); subplot(143), imshow(img_3); subplot(144), imshow(img_4);
- 再来处理一张整体偏亮的图片,即需要压缩灰度级。
代码如下:
% 读入图像
img_1 = imread('Fig0309(a)(washed_out_aerial_image).tif');
% 伽马变换,伽马值为0.6
img_2 = im2uint8(mat2gray(power(double(img_1), 3.0)));
% 伽马变换,伽马值为0.4
img_3 = im2uint8(mat2gray(power(double(img_1), 4.0)));
% 伽马变换,伽马值为0.3
img_4 = im2uint8(mat2gray(power(double(img_1), 5.0)));
% 显示图像
subplot(141), imshow(img_1);
subplot(142), imshow(img_2);
subplot(143), imshow(img_3);
subplot(144), imshow(img_4);
处理结果如下: