简体   繁体   中英

imwrite error during looping in matlab

Im newbie in Matlab and I have a problem to saving my processed images. So here is the command to do segmentation, cropping my images and save it in the specific path

Run.m

   Images_Number_Train=length(Input_Images);
   Urutan=1;
   for loop1=1:Images_Number_Train
   Images=imread(Input_Images(loop1));
   Label_Images=Label_Train(loop1);
   Sign = Crop_Sign(Images);
   Order= Save_Crop(Sign,Label_Images,Urutan);
   Urutan=Order;
   end

Save function

   function Urutan = Save_Crop(Sign,Label_Images,Urutan)

   Output_Path = 'E:\Images\Crop\Train\';
   if ~exist(Output_Path, 'dir')
   mkdir(Output_Training_Path);
   end
   newimagename = [Output_Path 'Images_Crop_' num2str(Urutan) '.pgm'];
   imwrite(Sign,newimagename);
   Urutan=Urutan+1;
   end

I have 120 Images and everytime I run the command, This program only can read images until 30 and then stop..

I got this error messege:

      Error using imwrite (line 421)
      Expected DATA to be nonempty.

      Error in Save_Crop (line 24)
      imwrite(Sign,newimagename);

and the value of Sign variable will be (after images 30th)

 val =

   Empty array: 0-by-0-by-3

Any suggestion, what I have to do

It looks like you actually have an empty image in there. (It has 0x0x3==0 elements).

If you don't think this is the case, make sure to carefully inspect your data. Otherwise, if you just want to skip it, wrap part of your code with an if statement like this:

if(~isempty(Images))
   %Do stuff
end

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM