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
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?
Sana Tayyeb
Sana Tayyeb 2015-5-10
by 3 dimensional i mean image that has RGB color channels. when i upload image by imread() size of the image is 680x680x3 but when i use uigetfile, after uploading file size changes to 1x12

请先登录,再进行评论。

回答(2 个)

Geoff Hayes
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?

Image Analyst
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]);

类别

Help CenterFile Exchange 中查找有关 Image Processing Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by