MATLAB imfinfo: Get Image File Info
In MATLAB, the imfinfo function can be used to obtain information about image files. The function returns a structure array where each element contains various properties and information about the image file.
The following is an example of using the imfinfo function to retrieve information about an image file.
file = 'image.jpg';
info = imfinfo(file);
% 输出图像的宽度和高度
width = info.Width;
height = info.Height;
disp(['图像尺寸:' num2str(width) 'x' num2str(height)]);
% 输出图像的色彩模式
colorType = info.ColorType;
disp(['色彩模式:' colorType]);
% 输出图像的位深度
bitDepth = info.BitDepth;
disp(['位深度:' num2str(bitDepth)]);
% 输出图像的文件大小
fileSize = info.FileSize;
disp(['文件大小:' num2str(fileSize) '字节']);
In the above example, we first specify the image file path to retrieve information and assign it to the file variable. Next, we use the imfinfo function to gather information about the image file and store the results in the info variable.
Next, we will use the properties in the info structure array to access the desired image information. For example, we can obtain the width and height of the image through info.Width and info.Height. The color mode of the image can be accessed through info.ColorType. The bit depth of the image can be obtained through info.BitDepth. The size of the image file can be accessed through info.FileSize.
Before using the imfinfo function to retrieve information about an image file, it is important to ensure that the image file exists and that MATLAB can access it properly.