1. Reading and display of Matlab images

Before we start, we need to create a .m file in the script and then run it. The path to the script to be replaced each time it is run. clc;clear;closeall; is often seen at the beginning of a file. So what is their function?

clc;%clc的作用就是清屏幕
clear;%clear是删除所有的变量
closeall;%close all是将所有打开的图片关掉。

1. Image reading

I=imread(‘pout.jpg’);

imread is a function to read an image. pout.jpg is the name of the image and can be read directly in any program. So, what if we want to read functions in other locations? Here we discuss several common situations.
(1) Read 1.jpg. This directory is in the current photo directory, and the script file is in the same directory as the photo.

I=imread(1.jpg’);

insert image description here
(2) Read E:\My Desktop\MATLAB\Exercise\1.jpg and obtain the absolute path of the photo. No matter which path the script is in, it will not affect the operation.

I=imread(‘E:\我的桌面\MATLAB\练习\1.jpg’);%绝对路径的读取

insert image description here

(3) Read 20 images in E:\My Desktop\Cut Flower Stamens\Saffron Pictures.

for i=1:20

 I=imread([‘D:\1023\25\’,num2str(i),.jpg’]);

end

Note that [ ] is added to ensure that this is a complete sentence. num2str(i) converts i from number to character form. This enables cyclic reading.

2. Display of images

imshow(I);%imshow显示按照原来的比例.

insert image description here
So when to use figure? When only one image is displayed in the program, just imshow directly. Then when there are many images, you need to use

figuure;imshow(I1);%I是之前的变量名
figure;imshow(I2);
figure;imshow(I3)

What if you want to display several pictures in one picture? The title is displayed above the image as a reminder.

clc;%clc的作用就是清屏幕
clear;%clear是删除所有的变量
close all;%close all是将所有打开的图片关掉。
I=imread('E:\我的桌面\MATLAB\练习\1.jpg');%绝对路径的读取
I1=imread('E:\我的桌面\MATLAB\练习\2.jpg');%绝对路径的读取
subplot(211);imshow(I);title('1');
subplot(212);imshow(I1);title('2');

insert image description here
The first 21 represents the distribution of 2 1 or 2 2, 3*3, etc. Arranged according to rows, starting from the first row are 1 2 .

Guess you like

Origin blog.csdn.net/qq_55433305/article/details/126823024