Matlab实现数字图像处理——点运算


本文介绍matlab代码实现图像处理中常见的点运算。

点运算

主程序:

f = imread('outman.jpg');
gray_f = rgb2gray(f);
figure();
imshow(gray_f),title('原图');
thresholding(gray_f, 0.35);
uptruncation(gray_f, 100);
downtruncation(gray_f, 100);
multi_thresholding(gray_f, 50, 150, 250, 100,150,200);
updowntruncation(gray_f, 200,100);
offset(gray_f, 50);
square(gray_f);
squareroot(gray_f);
inverse(gray_f);
scaling(gray_f); 
gammaCorrection(gray_f, 1, 1);
gammaCorrection(gray_f, 1, 0.5);
gammaCorrection(gray_f, 1, 2);

原图
子函数:

甄别

function thresholding(image, threshold)
threshold_number = threshold;
thresholding = imbinarize(image,threshold_number);
figure();
imshow(thresholding),title('甄别');
end

在这里插入图片描述

上截断

function uptruncation(image, floorholding)
[heighth, width] = size(image);
for i=1:heighth
    for j=1:width
        if (image(i,j)>floorholding)
            image(i,j)=floorholding;
        end
    end
end
figure();
imshow(image),title('上截断');
end

在这里插入图片描述

下截断

function xiajieduan(image, floorholding)
[heighth, width] = size(image);
for i=1:heighth
    for j=1:width
        if (image(i,j)<floorholding)
            image(i,j)=floorholding;
        end
    end
end
figure();
imshow(image),title('下截断');
end

在这里插入图片描述

上下截断

function updowntruncation(image, upholding, lowholding)
[heighth, width] = size(image);
for i=1:heighth
    for j=1:width
        if (image(i,j)>upholding)
            image(i,j)=upholding;
        end
        if (image(i,j)<lowholding)
            image(i,j)=lowholding;
        end
    end
end
figure();
imshow(image),title('上下截断');
end

在这里插入图片描述

多值甄别

function multi_thresholding(image, l1, l2, l3, t1, t2, t3)
    [heighth, width] = size(image);
for i=1:heighth
    for j=1:width
        if (image(i,j)<t1)
            image(i,j)=l1;
        end
        if (image(i,j)>t1 && image(i,j)<t2)
            image(i,j)=l2;
        end
        if (image(i,j)>t2 && image(i,j)<t3)
            image(i,j)=l3;
        end
        if (image(i,j)>t3)
            image(i,j)=255;
        end
    end
end
figure();
imshow(image),title('多值甄别');
end

在这里插入图片描述

补偿

function offset(image, offsetvalue)
    offsetim = image + offsetvalue;
    figure();
    imshow(offsetim),title('补偿');
end

在这里插入图片描述

平方

function square(image)
    squareim = image.*image;
    figure();
    imshow(squareim),title('平方');
end

在这里插入图片描述

方根

function squareroot(image)
    image = im2double(image); 
    squareroot = image.^(1/2);
    figure();
    imshow(squareroot),title('方根');
end

在这里插入图片描述

求反

function inverse(image)
[heighth, width] = size(image);
for i=1:heighth
    for j=1:width
        image(i,j)=255-image(i,j);
    end
end
figure();
imshow(image),title('求反');
end

在这里插入图片描述

放缩

function scaling(image)
scaling = image.*2;
figure();
imshow(scaling),title('放缩');
end

在这里插入图片描述

伽马变换

function gammaCorrection(name, a, gamma)
 r = name;
 r=im2double(r);                
 s = a * (r .^ gamma);
 figure();
 imshow(s), title(sprintf('Gamma: %0.1f',gamma));
end

在这里插入图片描述
在这里插入图片描述

在这里插入图片描述

  • 0
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值