Prev: Help me by checking this image accessing code using GUI.
Next: Access variables through list of variables
From: Dave on 28 Jun 2010 08:24 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.
From: Faraz Afzal on 28 Jun 2010 08:40 "Dave " <dbrucedev(a)gmail.com> wrote in message <i0a497$dli$1(a)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
From: Steven Lord on 28 Jun 2010 09:19 "Dave " <dbrucedev(a)gmail.com> wrote in message news:i0a47m$ane$1(a)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; Why do you have a button callback clearing the Command Window? > [filename,pathname] = uigetfile({'*.png';'*.jpg'},'Select Your > Images','Multiselect','on'); Remember that if the user selects multiple images in this dialog, filename and pathname will be CELL ARRAYS, not char arrays. Indexing into cell arrays using parentheses () extracts _cells_ while indexing into cell arrays using curly braces {} extracts _the contents of cells_. IMREAD expects you to pass it _a char array_ not a _cell array containing a char array_. -- Steve Lord slord(a)mathworks.com comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ To contact Technical Support use the Contact Us link on http://www.mathworks.com
From: Christopher on 29 Jun 2010 01:37
"Dave " <dbrucedev(a)gmail.com> wrote in message <i0a497$dli$1(a)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 |