Image reading for MATLAB image processing

1. Specified image reading——imreadfunction

insert image description here
Direct command line window input:

imread('background.jpeg');

Of course you can also try:

imread('background.jpeg')

tips : The read file name should be placed in the current file path, otherwise you will be given a piece of red

insert image description here

After the test, I found that there was either nothing or
insert image description here
a number, and I looked confused
insert image description here
. Well, I was also confused. I'm sorry it's been a long time, I didn't get used to it for a while.
At this time, as long as the clc is clicked, these numbers will disappear.
And " ; " mainly has the following three functions:
insert image description here

Now let's go through the eight classics

clc
I = imread('background.jpeg');
figure(1) %用于指定展示的画布,数字可以随意改。
imshow(I) %用于显示我们所需要查看的图像。

imread returns a 464×640×3 uint8 , array I of 8-bit unsigned integers.
insert image description here
You can also view the basic parameters of the image through the size function, which is convenient for subsequent image operations.

[m,n,z] = size(I);
m =
   464
n =
   640
z =
   3

But every time you need to input the name of the image file, it is not only cumbersome but also error-prone. If you want to make the image reading more convenient and fast, you need to use our uigetfile() function at this time.

2. Arbitrary image reading——uigetfilefunction

insert image description here
uigetfile() is used to open the file selection dialog box, as shown below
insert image description here

You can also specify the file type, range, file name, etc. we want to open.

[filename, pathname] = uigetfile({
    
    '*.jpg;*.tif;*.png;*.gif','All Image Files';...
            '*.*','All Files' },'载入图像',...
            fullfile(pwd, 'images'));

Among them, "..." is the continuation line number, which is used to connect the following lines with this line to form a longer command.
The pwd command writes the full path name of the current directory (from root) to standard output.
The fullfile() function concatenates the pwd and 'images' output value to get the full path to the desired image.
If you want to make reading more interesting, you can try the following, so I won’t explain it anymore:

[filename, pathname] = uigetfile({
    
    '*.jpg;*.tif;*.png;*.gif','All Image Files';...
            '*.*','All Files' },'载入图像',...
            fullfile(pwd, 'images'));
        if isequal(filename, 0) || isequal(pathname, 0)
            hs = warndlg('您得输入一幅图像');
            ht = findobj(hs, 'Type', 'text');
            set(ht, 'FontSize', 12, 'Unit', 'normal');
            set(hs, 'Resize', 'on');
            return;
        end
I = imread(fullfile(pathname, filename));
figure(2)
imshow(I) 

insert image description here

Guess you like

Origin blog.csdn.net/weixin_44886253/article/details/128501034