Error using imwrite Expected DATA to be non empty ???what is wrong with my code ???

5 vues (au cours des 30 derniers jours)
Israa Alqaraleh
Israa Alqaraleh le 29 Juin 2018
Commenté : Israa Alqaraleh le 30 Juin 2018

what is the problem and the solution of this problem . if I removed the line of imwrite it works and framing all the letters but I need to crop the letters and saves them for the next steps

while(j<m)
    while(i<n)
       rectangle('position',[i  j  60  115] , 'LineWidth',1,'EdgeColor','red');
       i= i+70; %45
       i= i+1;
       ccc = imcrop(crop , [i  j  60  115 ]);
        % str=sprintf('image%d.fig',i);
        % saveas(gcf,str);
       imwrite(ccc,strcat('hh',num2str(vv),'.bmp'));
       vv=vv+1;    
       s=s+i;
    end
     j= j+120; %58
     i= 1 ;
     j= j+1 ;
  end
  4 commentaires
Guillaume
Guillaume le 29 Juin 2018
I dont have any time to understand them
So, you can't waste time trying to understand your problem, but it's ok for us to waste time doing the same?
Rik
Rik le 29 Juin 2018
The code in a duplicate question is preceded by this (formatting is a guess):
[m, n] = size(crop);
[q,z] = size(crop);
i = 1 ; %column
j = 1 ; %row
%
figure(1),imshow(crop);
hold on;
s = 0 ;

Connectez-vous pour commenter.

Réponses (1)

Walter Roberson
Walter Roberson le 29 Juin 2018
[m, n] = size(crop);
If you did that with an RGB image, then m would get assigned size(crop,1) and n would get assigned size(crop,2) * size(crop,3), and size(crop,3) is 3 for RGB images, so n would end up getting assigned 3 times the number of columns. You have while(i<n) so i would go to 3 times the number of columns. When you tried to crop beyond the actual number of columns, imcrop would return an empty array, and you would not be able to imwrite() the empty array.
Any time you are working with images that are not absolutely certain to be 2D (that is, you specifically converted them to grayscale, or you are reading from a file format that does not support color images), then you should be careful about how you use size().

Catégories

En savoir plus sur Image Segmentation and Analysis dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by