Clear Filters
Clear Filters

How to use looping method to crop image dynamically (auto-cropping)?

11 views (last 30 days)
Hello. How to crop image using dynamic cropping method in matlab? Is there any example implementation codes?
Lets say, my original image have two different sizes which are 482 x 841 pixels and 608 x 865 pixels, so can I use loop step at first to extend the pixels which those that not enough pixels if I want to crop into 512 x 512 pixels? If the image size is enough to crop into 512 x512 pixels so no need to extend the pixels. I recently use this code:-
%To read input image
I=imread('1_776.jpg');
imfinfo('1_776.jpg')
First image, image size 482 x 841 px
Second image, image size 608 x 865 px
%To resize image
out = padarray(I, [10 10], 0, 'both');
imshow(out);
imwrite(out,'resize1.jpg');
but this is manual. Now I want it to automatically crop only specific area.
  1 Comment
Rik
Rik on 2 Jul 2024 at 11:28
So you want to crop images if they exceed 512 pixels in either height or width, and want to pad them with black if they are smaller than 512x512?

Sign in to comment.

Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!