How to input an image from the user using imread() command?

조회 수: 16 (최근 30일)
Afaq Ahmad
Afaq Ahmad 2020년 12월 31일
댓글: Afaq Ahmad 2021년 1월 6일
I am trying to input an image from the user using imread() command.If i simply put the location of the image in imread(), it converts the image into a "500*500*3 uint8" (in my case). I want to input (a random) image from the user and later on, convert it into pixels and then into the respective bits. How can I do it?
Thanks
  댓글 수: 2
Walter Roberson
Walter Roberson 2020년 12월 31일
[n, d] = uigetfile();
f = fullfile(d,n);
p = imread(f);
b = dec2bin(p,8) - '0';
Afaq Ahmad
Afaq Ahmad 2021년 1월 6일
Thank you! It worked.

댓글을 달려면 로그인하십시오.

답변 (2개)

Rik
Rik 2020년 12월 31일
You can extract data from the clipboard with the clipboard function. If you want the user to supply a file so you can use imread, you should use uigetfile to make the user select a file.
Make sure to deal with the user supplying invalid data or clicking cancel on the file picker window. You probably want to make sure the user gets an understandable error in such cases.

Image Analyst
Image Analyst 2020년 12월 31일
Try this:
% Have user browse for a file, from a specified "starting folder."
% For convenience in browsing, set a starting folder from which to browse.
startingFolder = pwd; % or 'C:\wherever';
if ~isfolder(startingFolder)
% If that folder doesn't exist, just start in the current folder.
startingFolder = pwd;
end
% Get the name of the file that the user wants to use.
defaultFileName = fullfile(startingFolder, '*.*');
[baseFileName, folder] = uigetfile(defaultFileName, 'Select a file');
if baseFileName == 0
% User clicked the Cancel button.
return;
end
fullFileName = fullfile(folder, baseFileName)
theImage = imread(fullFileName);
imshow(theImage);
Also, to see bits, see my attached bitplane viewer program.

카테고리

Help CenterFile Exchange에서 Environment and Settings에 대해 자세히 알아보기

제품


릴리스

R2014a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by