Why does uigetfile() changes the uploaded image dimensions? Is there any other way to upload image into GUI without changing images dimension?
1 次查看(过去 30 天)
显示 更早的评论
Hi, i am currently working on Uploading my image in to GUI. I am using uigetfile(). However upon uploading images by this way the whole image changes, its dimension changes and my following codes, which uses this image, halts to work. i am using a 3 dimensional image
[File_Name,Path] = uigetfile({'*.tif';'*.jpg';'*.png';'*.gif*'},'Image Selector');
A = importdata(fullfile(Path, File_Name), '\t', 15);
if File_Name==0
h = errordlg('Image not uploaded');
else
whos File_Name
figure
imshow(File_Name)
Please help me find where i am doing wrong and kindly tell me if there is another way to upload an image that doesn't changes its dimensions. Thanks in advance.
2 个评论
Geoff Hayes
2015-5-10
Sana - uigetfile will not change the dimensions of an image since it just provides a mechanism to allow the user to choose a file (in your case, an image). Please describe what you mean by how the image dimension changes? When do you realize that the dimensions have changed? And, when you mention that you are using a 3 dimensional image do you mean a 3D image or just an image that has the RGB colour channels?
回答(2 个)
Geoff Hayes
2015-5-10
Sana - the problem is not with uigetfile because it does not return a file. It just returns (in your use of it) a string to the file name and path (to the file). For example, if I run
[File_Name,Path] = uigetfile({'*.tif';'*.jpg';'*.png';'*.gif*'},'Image Selector');
and choose an image, I see that
File_Name =
abcd.gif
Path =
/Users/geoffhayes/Documents/MATLAB/test/
Each of these two variables are strings (character arrays) only. Your File_Name is probably a 1x12 character array. Is this the case?
Your use of imshow with the file name may also be a problem if your selected image is not within the MATLAB search path, and so you should pass the full path to this function as
imshow(fullfile(Path, File_Name));
Also, why do you call importdata? When do you use A?
0 个评论
Image Analyst
2015-5-10
Why don't you use imread() instead of importdata. Try this snippet:
% Have user browse for a file, from a specified "starting folder."
% For convenience in browsing, set a starting folder from which to browse.
startingFolder = 'C:\Program Files\MATLAB';
if ~exist(startingFolder, 'dir')
% 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)
rgbImage = imread(fullFileName); % Read color image into a 3D array.
% Get the dimensions of the image. numberOfColorBands should be = 3.
[rows, columns, numberOfColorBands] = size(rgbImage);
% Display the original color image.
imshow(rgbImage);
title('Original Color Image', 'FontSize', 20, 'Interpreter', 'None');
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'Outerposition', [0, 0, 1, 1]);
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!