How do I understand the following code?
2 次查看(过去 30 天)
显示 更早的评论
Hello,
I found this code online and I am trying to understand it for my study. I am unable to understand the following lines of code and I was wondering if someone will assist me in understanding. Specifically, I don't understand the part "%set the image size to suitable value" where it is giving scale and resizing the image and "%% image Resize"
%% Uploading input image
[filename,pathname] = uigetfile('*.*','Choose the input image');
im = imread([pathname,filename]);
% set the image size to suitable value
scale = 600/(max(size(im(:,:,1))));
im = imresize(im,scale*size(im(:,:,1)));
% % Image resize
[m,n,~] = size(im);
I would appreciate the assistance.
Thank you in advance.
0 个评论
采纳的回答
Adam Danz
2020-10-19
编辑:Adam Danz
2020-10-19
The best way to understand it is by using the help or doc commands to look up each function name. At the top of each page you'll see a brief description of the function, inputs and outputs.
Here's a very general description of each line
% CHOOSE A FILE
[filename,pathname] = uigetfile('*.*','Choose the input image');
% READ THE IMAGE FILE IN AS IMAGE DATA
im = imread([pathname,filename]);
% DETERMINE THE SCALE OF THE IMAGE DATA
% (max(size(...)) returns the images maximum dimension
% THE IMAGE DATA (im) IS AN nXmX3 ARRAY OF R-G-B- COLOR VALUES
% BUT THIS LINE ONLY REFERENCES THE "R" VALUES
scale = 600/(max(size(im(:,:,1))));
% SCALE THE IMAGE
im = imresize(im,scale*size(im(:,:,1)));
% GET THE NEW IMAGE SIZE
[m,n,~] = size(im);
You can use imshow(im) to see the image.
6 个评论
Adam Danz
2020-12-16
编辑:Adam Danz
2020-12-16
> It is possible that that is the reason why only R value is considered?
Possibly. I advise reading about the array returned by imread so you can you can understand what im is
> is it possible that an image will have all the same RGB values
Yes, when all 3 RGB values are the same, it's a shade of gray/black.white
rgb = repmat(0:.1:1, 3,1)'
scatter(1:11,.5.*ones(1,11),250,rgb,'filled','MarkerEdgeColor','k')
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Image Processing Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!