I cant use other solutions such mentioned in other conversations because I dont have any time to understand them, so please help me with the same code
Error using imwrite Expected DATA to be non empty ???what is wrong with my code ???
5 次查看(过去 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
回答(1 个)
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 Exchange 中查找有关 Image Segmentation and Analysis 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!