Unable to perform assignment because the indices on the left side are not compatible with the size of the right side

Hello,
I am trying to crop different parts of an image. the objects cannot be attained automatically or by coordinates so I have to crop them manually.
The code that I am using is:
im = imshow('DJI_0834.jpg');
for i = 1:30
cropped(i)=imcrop(im)
end
It shows the image with the crop cursor but when I try to save the first crop it shows the error message in the title.
I also have a question if I can automatically save them as JPG files after finishing the crop.
Thanks.

 Risposta accettata

imcrop return an image (2D or a 3D array). You cannot assign it as an element of a numeric array. You need a cell array
im = imshow('DJI_0834.jpg');
cropped = cell(1, 30);
for i = 1:30
cropped{i}=imcrop(im);
end
Access them using brace indexing
cropped{1}; % first cropped image
cropped{2}; % second cropped image
..
..
cropped{end}; % last cropped image

5 Commenti

Thank you, It worked for croping. I am still have one problem with saving all the data in the cell as images format. is ther a way to do so ?
I mean, after getting the cropped images in a cell array, I want now to extract them as jpg files in order to use them in a further workflow
Yes, you can save them using imwrite()
for i = 1:numel(cropped)
imwrite(cropped{i}, sprintf('image%2d.png', i))
end

Accedi per commentare.

Più risposte (0)

Categorie

Prodotti

Release

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by