Clear Filters
Clear Filters

How to crop image into 256 x 256 x 3 if the original image is 841 x 482 x 3 uint8 if using the centroide of the lesion with x_cent = 720 and y_cent = 151?

6 views (last 30 days)
Here my full codes to crop:
centroide=[x_cent y_cent];
I2=imcrop(I,[xmin ymin size_of_cropped_img size_of_cropped_img])
After I crop the image, the output is appeared and save not as 256 x 256 x 3 but 251 x 257 x 3 uint8.
How to crop with exact dimension I want if the original image is 841 x 482 x 3 uint8?

Accepted Answer

Walter Roberson
Walter Roberson on 13 Jun 2023
I2 = I(ymin:ymin+size_of_cropped_img-1, xmin:xmin+size_of_cropped_img-1, :);
DGM on 14 Jun 2023
Edited: DGM on 14 Jun 2023
You're trying to crop a region that extends outside the image area. You'll need to decide what should happen. If the missing area is to be filled, how should it be filled?
Dayangku Nur Faizah Pengiran Mohamad
Edited: Dayangku Nur Faizah Pengiran Mohamad on 24 Jun 2023
Hello Sir, I got the answer for this question. I extend the size of image using out = padarray(I, [10 10], 0, 'both'); , and then crop it by the size I want, thank you for you concern for this matter.

Sign in to comment.

More Answers (0)


Community Treasure Hunt

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

Start Hunting!