MATLAB一些简单的图像处理程序

1

I=imread('pout.tif');
figure,imshow(I);
[m,n]=size(I);
Inew=zeros(floor(m/2),n);
for i=1:m
    for j=1:n
    Inew(i,j)=I(2*i-1,j);
    end
end
figure,imshow(uint8(Inew))

2

clc
clear 
x=0:255;
y1=x;
figure,
plot(x,y1,'r')
hold on
y2=255:-1:0;
plot(x,y2,'b')
ylog=255*(log(x+1)/log(256));
plot(x,ylog,'g+')
yexp=255*x.^3/255^3;
plot(x,yexp,'y+')
c=255/255^3;
ynthroot=nthroot((x/c),3);
plot(x,ynthroot,'yo')
3

I=imread('moon.tif');
I=double(I);
[m,n]=size(I);
for i=1:m
    for j=1:n
        if I(i,j)<100
            Inew(i,j)=3*I(i,j);
        elseif I(i,j)>200
            Inew(i,j)=0.8*I(i,j);
        else
            Inew(i,j)=I(i,j);
        end
    end
end
figure,imshow(Inew,[])
4

clear
clc
I=imread('moon.tif');
I=im2double(I);
[m,n]=size(I);
for i=1:m
    for j=1:n
        Inew(i,j)=I(i,j)^0.2;
    end
end
figure,imshow(I,[])
figure,imshow(Inew,[])
5

每个像素点的计算与查找表的比较

clear
clc
I=imread('moon.tif');
I=im2double(I);
[m,n]=size(I);
%循环实现
tic
for i=1:m
    for j=1:n
        Inew(i,j)=255*log(I(i,j)+1)/log(256);
    end
end
toc
%查找表
tic
x=0:255;
c=255/log(256);
y=c*log(x+1);
I_log=uint8(y(x+1));
figure,plot(x,y)
toc
figure,imshow(I_log,[])
figure,imshow(I,[])
figure,imshow(Inew,[])

6

显示一幅图像的直方图

I=imread('pout.tif');
figure,imshow(I)
[m,n]=size(I);
h=zeros(1,256);
for k=0:255
    for i=1:m
        for j=1:n
            if(I(i,j)==k)
               h(k+1)=h(k+1)+1;
            end
        end
    end
end
figure,bar(h)
改进后代码:

I=imread('pout.tif');
figure,imshow(I)
[m,n]=size(I);
h=zeros(1,256);
for i=1:m
    for j=1:n
        h(I(i,j)+1)=h(I(i,j)+1)+1;
    end
end
figure,bar(h)

将一幅图经直方图均衡化处理

I=imread('pout.tif');
figure,imshow(I)
[m,n]=size(I);
h=zeros(1,256);
for i=1:m
    for j=1:n
        h(I(i,j)+1)=h(I(i,j)+1)+1;
    end
end
figure,bar(h)
p=h/(m*n);
sum=0;
for i=1:256
    sum=sum+p(i);
    y(i)=round(sum*255);
end
for i=1:m
    for j=1:n
        Inew(i,j)=y(I(i,j)+1);
    end
end

figure,imshow(unit8(Inew))

7 邻域处理

I=imread('pout.tif');
I=double(I);
%卷积模板的不同处理效果不同
%M=ones(3,3)/9;将一幅图模糊处理; M=[0 -1 0;-1 5 -1;0 -1 0];将一幅图锐化处理,改变中心位置的值有不同效果
%M=[1 1 1;0 0 0;-1 -1 -1];指出原始图像中水平边缘存在位置的图像;M=[1 0 -1;1 0 -1;1 0 -1];指出原始图像中垂直边缘存在位置的图像
M=ones(3,3)/9;
[m,n]=size(I);
Inew=zeros(m,n);
%从2开始到m-1忽略边界
for i=2:m-1     
    for j=2:n-1
      Inew(i,j)=I(i-1,j-1)*M(1,1)+I(i-1,j)*M(1,2)+...
      I(i-1,j+1)*M(1,3)+I(i,j-1)*M(2,1)+I(i,j)*M(2,2)+...
      I(i,j+1)*M(2,3)+I(i+1,j-1)*M(3,1)+I(i+1,j)*M(3,2)+... 
      I(i+1,j+1)*M(3,3);
    end
end
figure,imshow(uint8(Inew))









©️2020 CSDN 皮肤主题: 大白 设计师: CSDN官方博客 返回首页
实付0元
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值