uiwait and warning dialog problem

Hi,
I use a load image button in GUI that contains the following code:
[path, file] = uigetfile({'*.jpg;*.gif','All Image Files'},' Select image')
imgFile = strcat(path,file);
I = imread(imgFile);
imgInfo = imfinfo(imgFile);
x=imgInfo.ColorType;
while x=='grayscale'
uiwait(warndlg('Please select a color image'));
end
I have to two problems: 1) When I click a grayscale image the warning dialog popups but I have to press the load image button in order to cancel it. I wish to click the ok causing the warning dialog to disappear. How do I do it? 2) When I exit run of the matlab code the warning dialog still appears and I cannot closed it. How to solve it?
Thanks.

 Risposta accettata

Image Analyst
Image Analyst il 6 Mag 2013
Modificato: Image Analyst il 6 Mag 2013
Use this more robust code:
while true;
[baseFileName, folder] = uigetfile({'*.jpg;*.gif;*.png;*.tif;*.bmp','All Image Files'},' Select image')
if baseFileName == 0;
% They canceled out.
return;
end
fullFileName = fullfile(folder, baseFileName)
[originalImage, storedColorMap] = imread(fullFileName);
[rows, columns, numberOfColorChannels] = size(originalImage)
if numberOfColorChannels == 3 % Will be 3 for color.
% It's a color image.
uiwait(warndlg('Please select a grayscale image, not a color image.')); % Will Loop again
else
% It's an indexed or gray image.
if ~isempty(storedColorMap)
% It's an indexed, not grayscale, image.
uiwait(warndlg('Please select a grayscale image, not an indexed image.')); % Will Loop again
else
break; % It's color so continue on.
end
end
end
imshow(originalImage);

3 Commenti

Ely Raz
Ely Raz il 6 Mag 2013
Modificato: Ely Raz il 6 Mag 2013
Thanks. My aim is to only allow color images. So I modifed your excelent code. Any comments?
....
if numberOfColorChannels < 3 % Will be 3 for color.
% It's a not a color image.
uiwait(warndlg('Please select a color image, not a gray scale image.')); % Will Loop again
else
% It's an indexed or color image.
if ~isempty(storedColorMap)
% It's an indexed, not grayscale, image.
uiwait(warndlg('PPlease select a color image, not an indexed image.')); % Will Loop again
else
....
Image Analyst
Image Analyst il 6 Mag 2013
Modificato: Image Analyst il 6 Mag 2013
Looks like it should work. If it does, go with it.
Sure thing. Thanks again

Accedi per commentare.

Più risposte (0)

Categorie

Community Treasure Hunt

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

Start Hunting!

Translated by