Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Help me by checking this image accessing code using GUI.

Subject: Help me by checking this image accessing code using GUI.

From: Dave

Date: 28 Jun, 2010 12:24:07

Message: 1 of 3

I need to access a bunch of images from a folder.For this purpose I used GUIDE tool and I got different errors in different situations as below.

==>Trial 1:

function pushbutton1_Callback(hObject, eventdata, handles)
clc;
[filename,pathname] = uigetfile({'*.png';'*.jpg'},'Select Your Images','Multiselect','on');
%imagename = strcat(pathname,filename);
msgbox(pathname);
flength = length(filename);
plength = length(pathname);
for pcount=1:plength
    for flength=1:flength
        pname = pathname(plength);
        fname = filename(flength);
        ifname=strcat(pname,fname);
        msgbox(ifname);
        inimage = imread(ifname);
        figure,imshow(inimage);
    end
end

Error I got:
?? Conversion to logical from cell is not
possible.
Error in ==> imread at 282
if (strfind(filename, '://'))
Error in ==> GUIDEMO1>pushbutton1_Callback at
91
      inimage = imread(ifname);
Error in ==> gui_mainfcn at 96
       feval(varargin{:});
Error in ==> GUIDEMO1 at 42
    gui_mainfcn(gui_State, varargin{:});
??? Error while evaluating uicontrol Callback

This may be due to the back slash(\) that appears at the end of the path name and at the beginning of the file name .My question is how to remove that back space??

==>Trial2:

 I concatenated both filename and pathname into imagename(it is a cell).
without any back slash problem,but when I tried to use the function imread().

function pushbutton1_Callback(hObject, eventdata, handles)
clc;
[filename,pathname] = uigetfile({'*.png';'*.jpg'},'Select Your Images','Multiselect','on');
imagename = strcat(pathname,filename);
msgbox(imagename);
listlength =length(imagename);
%celldisp(imagename);
%sizeinstr = num2str(listlength);
%msgbox(sizeinstr)
%x=iscellstr(imagename)
for count=1:listlength
    location=imagename(1,count);
    msgbox(location);
    imageread = imread(location);
    imshow(imageread);
    image2=rgb2gray(image1);
    image3=im2uint8(image1);
    figure,imshow(image3);
    cnt = num2str(count);
    msgbox(cnt)
end

Error I got(Same as previous one):

??? Conversion to logical from cell is not
possible.
Error in ==> imread at 282
if (strfind(filename, '://'))
Error in ==> GUIDEMO1>pushbutton1_Callback at
105
    imageread = imread(location);
Error in ==> gui_mainfcn at 96
        feval(varargin{:});
Error in ==> GUIDEMO1 at 42
    gui_mainfcn(gui_State, varargin{:});
??? Error while evaluating uicontrol Callback


==>Trial3:


Now Iam able to view the images without using imread,rgb2gray,im2uint8 functions by accessing the image as imagename{1,count}

for count=1:listlength
    image=imagename{1,count};
    %msgbox(location);
    imshow(imaged);
    image2=rgb2gray(image);
    image3=im2uint8(image2);
    figure,imshow(image3);
    cnt = num2str(count);
    msgbox(cnt)
end

Error:
??? Error using ==> rgb2gray>parse_inputs at 82
MAP must be a m x 3 array.
Error in ==> rgb2gray at 35
X = parse_inputs(varargin{:});
Error in ==> GUIDEMO1>pushbutton1_Callback at
107
    image2=rgb2gray(location);
Error in ==> gui_mainfcn at 96
        feval(varargin{:});
Error in ==> GUIDEMO1 at 42
    gui_mainfcn(gui_State, varargin{:});
??? Error while evaluating uicontrol Callback


My query is a bit lengthy please excuse me but, I am at the end of my task.At this point I got the above problem.Could any one help me out.

Regards,
Dave.

Subject: Help me by checking this image accessing code using GUI.

From: Faraz Afzal

Date: 28 Jun, 2010 12:40:41

Message: 2 of 3

"Dave " <dbrucedev@gmail.com> wrote in message <i0a497$dli$1@fred.mathworks.com>...
> I need to access a bunch of images from a folder.For this purpose I used GUIDE tool and I got different errors in different situations as below.
>
> ==>Trial 1:
>
> function pushbutton1_Callback(hObject, eventdata, handles)
> clc;
> [filename,pathname] = uigetfile({'*.png';'*.jpg'},'Select Your Images','Multiselect','on');
> %imagename = strcat(pathname,filename);
> msgbox(pathname);
> flength = length(filename);
> plength = length(pathname);
> for pcount=1:plength
> for flength=1:flength
> pname = pathname(plength);
> fname = filename(flength);
> ifname=strcat(pname,fname);
> msgbox(ifname);
> inimage = imread(ifname);
> figure,imshow(inimage);
> end
> end
>
> Error I got:
> ?? Conversion to logical from cell is not
> possible.
> Error in ==> imread at 282
> if (strfind(filename, '://'))
> Error in ==> GUIDEMO1>pushbutton1_Callback at
> 91
> inimage = imread(ifname);
> Error in ==> gui_mainfcn at 96
> feval(varargin{:});
> Error in ==> GUIDEMO1 at 42
> gui_mainfcn(gui_State, varargin{:});
> ??? Error while evaluating uicontrol Callback
>
> This may be due to the back slash(\) that appears at the end of the path name and at the beginning of the file name .My question is how to remove that back space??
>
> ==>Trial2:
>
> I concatenated both filename and pathname into imagename(it is a cell).
> without any back slash problem,but when I tried to use the function imread().
>
> function pushbutton1_Callback(hObject, eventdata, handles)
> clc;
> [filename,pathname] = uigetfile({'*.png';'*.jpg'},'Select Your Images','Multiselect','on');
> imagename = strcat(pathname,filename);
> msgbox(imagename);
> listlength =length(imagename);
> %celldisp(imagename);
> %sizeinstr = num2str(listlength);
> %msgbox(sizeinstr)
> %x=iscellstr(imagename)
> for count=1:listlength
> location=imagename(1,count);
> msgbox(location);
> imageread = imread(location);
> imshow(imageread);
> image2=rgb2gray(image1);
> image3=im2uint8(image1);
> figure,imshow(image3);
> cnt = num2str(count);
> msgbox(cnt)
> end
>
> Error I got(Same as previous one):
>
> ??? Conversion to logical from cell is not
> possible.
> Error in ==> imread at 282
> if (strfind(filename, '://'))
> Error in ==> GUIDEMO1>pushbutton1_Callback at
> 105
> imageread = imread(location);
> Error in ==> gui_mainfcn at 96
> feval(varargin{:});
> Error in ==> GUIDEMO1 at 42
> gui_mainfcn(gui_State, varargin{:});
> ??? Error while evaluating uicontrol Callback
>
>
> ==>Trial3:
>
>
> Now Iam able to view the images without using imread,rgb2gray,im2uint8 functions by accessing the image as imagename{1,count}
>
> for count=1:listlength
> image=imagename{1,count};
> %msgbox(location);
> imshow(imaged);
> image2=rgb2gray(image);
> image3=im2uint8(image2);
> figure,imshow(image3);
> cnt = num2str(count);
> msgbox(cnt)
> end
>
> Error:
> ??? Error using ==> rgb2gray>parse_inputs at 82
> MAP must be a m x 3 array.
> Error in ==> rgb2gray at 35
> X = parse_inputs(varargin{:});
> Error in ==> GUIDEMO1>pushbutton1_Callback at
> 107
> image2=rgb2gray(location);
> Error in ==> gui_mainfcn at 96
> feval(varargin{:});
> Error in ==> GUIDEMO1 at 42
> gui_mainfcn(gui_State, varargin{:});
> ??? Error while evaluating uicontrol Callback
>
>
> My query is a bit lengthy please excuse me but, I am at the end of my task.At this point I got the above problem.Could any one help me out.
>
> Regards,
> Dave.

Hiya Dave..

your problem is quite interesting.. Good that you posted here..
Well I m really busy to read out ur code , but let me tell u ho wu will get rid of ur cell to logical is not possible.. look through ur code and u might be using somewhere curly braces.. {} where they are not required.. Use parantheses () instead.. try and u will get rid of this error..And it is possible that u get ur code working.... I will look into it in details..
Let me know if it helped..
Regards,
Muhammad Faraz

Subject: Help me by checking this image accessing code using GUI.

From: Christopher

Date: 29 Jun, 2010 05:37:03

Message: 3 of 3

"Dave " <dbrucedev@gmail.com> wrote in message <i0a497$dli$1@fred.mathworks.com>...
> I need to access a bunch of images from a folder.For this purpose I used GUIDE tool and I got different errors in different situations as below.
>
> ==>Trial 1:
>
> function pushbutton1_Callback(hObject, eventdata, handles)
> clc;
> [filename,pathname] = uigetfile({'*.png';'*.jpg'},'Select Your Images','Multiselect','on');
> %imagename = strcat(pathname,filename);
> msgbox(pathname);
> flength = length(filename);
> plength = length(pathname);
> for pcount=1:plength
> for flength=1:flength
> pname = pathname(plength);
> fname = filename(flength);
> ifname=strcat(pname,fname);
> msgbox(ifname);
> inimage = imread(ifname);
> figure,imshow(inimage);
> end
> end
>
> Error I got:
> ?? Conversion to logical from cell is not
> possible.
> Error in ==> imread at 282
> if (strfind(filename, '://'))
> Error in ==> GUIDEMO1>pushbutton1_Callback at
> 91
> inimage = imread(ifname);
> Error in ==> gui_mainfcn at 96
> feval(varargin{:});
> Error in ==> GUIDEMO1 at 42
> gui_mainfcn(gui_State, varargin{:});
> ??? Error while evaluating uicontrol Callback
>
> This may be due to the back slash(\) that appears at the end of the path name and at the beginning of the file name .My question is how to remove that back space??
>
> ==>Trial2:
>
> I concatenated both filename and pathname into imagename(it is a cell).
> without any back slash problem,but when I tried to use the function imread().
>
> function pushbutton1_Callback(hObject, eventdata, handles)
> clc;
> [filename,pathname] = uigetfile({'*.png';'*.jpg'},'Select Your Images','Multiselect','on');
> imagename = strcat(pathname,filename);
> msgbox(imagename);
> listlength =length(imagename);
> %celldisp(imagename);
> %sizeinstr = num2str(listlength);
> %msgbox(sizeinstr)
> %x=iscellstr(imagename)
> for count=1:listlength
> location=imagename(1,count);
> msgbox(location);
> imageread = imread(location);
> imshow(imageread);
> image2=rgb2gray(image1);
> image3=im2uint8(image1);
> figure,imshow(image3);
> cnt = num2str(count);
> msgbox(cnt)
> end
>
> Error I got(Same as previous one):
>
> ??? Conversion to logical from cell is not
> possible.
> Error in ==> imread at 282
> if (strfind(filename, '://'))
> Error in ==> GUIDEMO1>pushbutton1_Callback at
> 105
> imageread = imread(location);
> Error in ==> gui_mainfcn at 96
> feval(varargin{:});
> Error in ==> GUIDEMO1 at 42
> gui_mainfcn(gui_State, varargin{:});
> ??? Error while evaluating uicontrol Callback
>
>
> ==>Trial3:
>
>
> Now Iam able to view the images without using imread,rgb2gray,im2uint8 functions by accessing the image as imagename{1,count}
>
> for count=1:listlength
> image=imagename{1,count};
> %msgbox(location);
> imshow(imaged);
> image2=rgb2gray(image);
> image3=im2uint8(image2);
> figure,imshow(image3);
> cnt = num2str(count);
> msgbox(cnt)
> end
>
> Error:
> ??? Error using ==> rgb2gray>parse_inputs at 82
> MAP must be a m x 3 array.
> Error in ==> rgb2gray at 35
> X = parse_inputs(varargin{:});
> Error in ==> GUIDEMO1>pushbutton1_Callback at
> 107
> image2=rgb2gray(location);
> Error in ==> gui_mainfcn at 96
> feval(varargin{:});
> Error in ==> GUIDEMO1 at 42
> gui_mainfcn(gui_State, varargin{:});
> ??? Error while evaluating uicontrol Callback
>
>
> My query is a bit lengthy please excuse me but, I am at the end of my task.At this point I got the above problem.Could any one help me out.
>
> Regards,
> Dave.

Trial #1 is poor because you are assuming you will have multiple pathname's. In reality you can only have one path returned from the uigetfile() function as far as I know. As a result,

plength = length(pathname)

returns the length of the pathname string and then

pname = pathname(plength);

returns the last character of the pathname (i.e pname = '\') when in reality you wanted the entire pathname. So when you attempt to read this file it cannot be found.

Trial # 2 is a little better - now you are getting the entire location inclusive of the pathname into your imagename. I was a bit sceptical with your use of strcat() but it seemed to work even with the dimensions (although I never investigated fully). The only problem you have now with Trial # 2 is that you are attempting to use image functions

rgb2gray() and im2uint8()

on a string. Remember the variable 'image' is just a string stating the location of the file. rgb2gray() and im2uint8() both work on numerical arrays. Therefore, before attempting the conversion, read in the actual image data with:

imageData = imread(image);

and then perform the conversions on this variable:

image2 = rgb2gray(imageData);
image3 = rgb2uint8(imageData);

Hope this helps,

Chris

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us