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

5 ビュー (過去 30 日間)
Israa Alqaraleh
Israa Alqaraleh 2018 年 6 月 29 日
コメント済み: Israa Alqaraleh 2018 年 6 月 30 日

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 件のコメント
Guillaume
Guillaume 2018 年 6 月 29 日
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 2018 年 6 月 29 日
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 ;

サインインしてコメントする。

回答 (1 件)

Walter Roberson
Walter Roberson 2018 年 6 月 29 日
[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().

カテゴリ

Help Center および File ExchangeImage Segmentation and Analysis についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by