B站台湾大学郭彦甫|MATLAB 学习笔记|08 图像处理I Image Processing

MATLAB学习笔记(08 图像处理I Image Processing)

1. 基本操作

  • 读取图像 imread()
  • 展示图像 imshow()
clear, close all
I = imread('pout.tif'); %read,这幅图的命名为‘pout.tif’
imshow(I); %show

pout.tif 为MATLAB自带图像,无需手动添加

-c200
  • 获得图像信息 imageinfo()

  • 获得图像像素信息 imtool()

-c

2. matlab 内建图像算法

函数 内容
imabsdiff Absolute difference of two images
imadd Add two images or add constant to image
imapplymatrix Linear combination of color channels
imcomplement Complement image
imdivide Divide one image into another or divide image by constant
imlincomb Linear combination of images
immultiply Multiply two images or multiply image by constant
imsubtract Subtract one image from another or subtract constant from image

3. 图像相乘、相加

  • 图像相乘 immultiply()
I=imread('rice.png');
subplot(1,2,1); imshow(I);
J=immultiply(I, 1.5);       %图像的每个像素乘以1.5
subplot(1,2,2); imshow(J);

P16 exercise

题目:How to reduce the brightness of the image?

-c200

要求不能使用 immultiply() 函数,自己写一个函数使整个图像的像素值乘以1.5

此处题目为减少图像亮度,代码效果是增加图像亮度,稍加修改即可

I=imread('rice.png');
for i=1:size(I,1)
    for j=1:size(I,2)
        a(i,j)=I(i,j)+20;       %用一个数组a,将I中的数据复制到a中,且每个像素的灰度值加20
    end
    
end

subplot(1,2,1);imshow(I);title('Origin Picture rice');
subplot(1,2,2);imshow(a);title('Last Picture rice');
-c400
  • 图像相加 imadd()
I=imread('rice.png');
J=imread('cameraman.tif'); K=imadd(I,J); %图像相加
subplot(1,3,1); imshow(I);
subplot(1,3,2); imshow(K);
subplot(1,3,3); imshow(J);
-c400

P18 exercise

题目:Adjust the “brightness” and “contrast” of rice.png and display it on the screen

-c200
I=imread('rice.png');
for i=1:size(I,1)
    for j=1:size(I,2)
        if I(i,j)>127       %原图像素灰度值大于127的像素值增大,原图像素灰度值小于127的像素值减小
        a(i,j)=I(i,j)+40;    %以增大对比度,亮的越亮,暗的越暗
        else a(i,j)=I(i,j)-40;
        end
        a(i,j)=a(i,j)+20;     %所有像素灰度值增大,增大亮度
    end
    
end

subplot(1,2,1);imshow(I);title('Origin Picture rice');
subplot(1,2,2);imshow(a);title('Last Picture rice');
-c400

4. 直方图

imhist()

P20 exercise

题目:Plot the histograms of the images before and after the “brightness” and “contrast” adjustment for rice.png

I=imread('rice.png');
for i=1:size(I,1)
    for j=1:size(I,2)
        if I(i,j)>127       %原图像素灰度值大于127的像素值增大,原图像素灰度值小于127的像素值减小
        a(i,j)=I(i,j)+40;    %以增大对比度,亮的越亮,暗的越暗
        else a(i,j)=I(i,j)-40;
        end
        a(i,j)=a(i,j)+20;     %所有像素灰度值增大,增大亮度
    end
    
end

subplot(2,2,1);imshow(I);title('Origin Picture rice');
subplot(2,2,2);imshow(a);title('Last Picture rice');
subplot(2,2,3);imhist(I);title('Origin Picture rice histogram');
subplot(2,2,4);imhist(a);title('Last Picture rice histogram');
-c400
  • 直方图均衡化 Histogram Equalization
    histeq()
I = imread('pout.tif'); I2 = histeq(I);
subplot(1,4,1); imhist(I);
subplot(1,4,2); imshow(I);
subplot(1,4,3); imshow(I2);
subplot(1,4,4); imhist(I2);
-c

P22 exercise (未)

题目:Write your own equalization function, try it on pout.tif, and display it on the screen

把灰度级概率最大的原灰度值放到灰度级概率最小的灰度级当中
怎么读取灰度级概率呢??

5. 图像几何转换 (Geometric Transformation)

目的是改变图像的位置,不改变图像内的像素值

  • 图像转换矩阵 (2D)
-c400
  • 图像转换 imrotate() (逆时针方向转换)
I = imread('rice.png'); subplot(1,2,1);
imshow(I); J = imrotate(I, 35, 'bilinear');
subplot(1,2,2); imshow(J);
size(I)
size(J)
-c400

P27 exercise(未)

题目:In two dimensions, rotation of a point (𝑥,𝑦) for angle 𝜃 “counter-clockwise” can be written as:

[xy]=[cosθsinθsinθcosθ][xy]

6. 图像存储

imwrite(I, 'pout2.png');
posted @   一抹微瀾  阅读(239)  评论(0编辑  收藏  举报
编辑推荐:
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
阅读排行:
· winform 绘制太阳,地球,月球 运作规律
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 上周热点回顾(3.3-3.9)
· AI 智能体引爆开源社区「GitHub 热点速览」
· 写一个简单的SQL生成工具
点击右上角即可分享
微信分享提示