matlab图像去毛刺_MATLAB数字图像处理

这篇博客详细介绍了如何使用MATLAB进行图像处理,包括读取、显示、缩放和旋转图像,以及图像的格式转换。重点讲解了图像去毛刺的技巧,涉及到图像的直方图、均衡化、平滑化和边缘检测等关键步骤,旨在帮助读者掌握MATLAB在数字图像处理中的应用。
摘要由CSDN通过智能技术生成

工具: MATLAB;

动机:使用 MATLAB toolbox 程序设计相对简单,通过初步学习一些图像处理的常见技术,帮助建立这方面的技能体系;

面向对象:有过经验,但是一头雾水的我。

1 图像、视频文件读取

clear all; close all; clc;

% Read an image

A = imread('lena.jpg');

% Display the read image

figure, imshow(A);

% Print height, width and number of channels of the read image

height = size(A, 1);

width = size(A, 2);

number_of_channels = size(A, 3);

% Resize the image to 2x and display

B = imresize(A, 2.0);

figure, imshow(B);

% Rotate the image 逆时针旋转

C = imrotate(A, 90);

figure, imshow(C);

关键点:imread,figure(imshow),size获取高度,宽度,图像通道数的参数,图像缩放,旋转。

clear all; close all; clc;

% Read an image

A = imread('lena.jpg');

% Translate the image

A_trans = imtranslate(A, [5 15]);

% Write the transformed image to disk

imwrite(A_trans, 'newlena.jpg');

figure,imshow(A_trans);

关键:imwrite及其调用前做的工作。

1-1 视频读取(选看)

clear all; close all; clc;

% Initialize an object for reading video

videoObj = vision.VideoFileReader('video1.mp4', 'ImageColorSpace', 'RGB');

% Get video frame size and frame rate

S = info(videoObj);

width = S.VideoSize(1);

height = S.VideoSize(end);

frame_rate = S.VideoFrameRate;

% Get individual video frames

image_data = step(videoObj);

% Run the loop until all frames have been displayed

while ~isDone(videoObj)

% Display video frame one by one

imshow(image_data);

image_data = step(videoObj);

end

% Release the object for reading video

release(videoObj);

关键:step,其流程reader读取生成对象,得到信息,逐帧显示 , PS:视频教程中有另外一种实现。

3 图像格式

3.1 RGB、灰度图片

clear all; close all; clc;

% Read a RGB image

A = imread('lena.jpg');

% Verify number of channels

number_of_channels = size(A, 3)

% Convert RGB image to Grayscale

A_gray = rgb2gray(A);

number_of_channels2 = size(A_gray, 3)

figure, subplot(1, 2, 1), imshow(A), title('Input RGB image');

subplot(1, 2, 2), imshow(A_gray), title('Converted Grayscale image');

f7a8eb2b4c91d398a0a80845dd7c82d5.png

关键:灰度图像颜色通道位1,rgb图像颜色通道数是3,subplot 显示多个图像,便于查看。

clear all; close all; clc;

% Read a RGB image

A = imread('lena.jpg');

% Extract individual R, G & B channels from RGB image

R = A(:, :, 1);

G = A(:, :, 2);

B = A(:, :, 3);

% Convert RGB image to HSV color space

A_hsv = rgb2hsv(A);

% Extract individual H, S & V channels from HSV image

H = A_hsv(:, :, 1);

S = A_hsv(:, :, 2);

V = A_hsv(:, :, 3);

% Display the read RGB image and HSV converted image

figure, subplot(1, 2, 1), imshow(A), title('Read RGB image');

subplot(1, 2, 2), imshow(A_hsv), title('Converted HSV image');

% Displaying individual image channels.

figure, subplot(1, 3, 1), imshow(S), title('Saturation channel');

subplot(1, 3, 2), imshow(H), title('Hue channel');

subplot(1, 3, 3), imshow(V), title('Value channel');

2c29f3e2a5a869586e19dbe6f4b886a5.png

关键:R、G、B、H、S、V 都是提取空间域(矩阵表示)的信息

  • 3
    点赞
  • 25
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值