Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Crop Image with Fixed Ratio

Subject: Crop Image with Fixed Ratio

From: Nehal

Date: 27 Sep, 2010 10:02:04

Message: 1 of 6

I have some multiple dimensional images. For example 150x250, 157x253, ...... ect.
Now I want to resize each images having the row and column ratio fixed.

If I use imresize function, it resizes properly but the shape of the object inside the image is changed/distorted. Because it stretches or squeezes the image. I do not want to change the shape of the object on the image. That is why I want to resize the image with keeping the ratio of the image same.

In my case, the image is a binary image with black background and the object is a white hand. And my required dimension is 50x50.
here is a sample of my image:
http://img20.imageshack.us/img20/8523/sampleimage.png

The steps I need:
1. Matlab will resize the image (for example 150x250) into 30x50 (because of the fixed ratio). Here the largest value between the row and column value will be resized and the other one will be resized having the ratio same.
In my example,
resized row = 30
resized column = 50

2. Now, I want to add 10 black rows on the both side of the resized image. Which means: (10+30+10) = 50 rows (which is my required row size)
and the columns will not be changed.
This is how I can make the object placed in the center of the image.

Can anyone plz help me..?

Subject: Crop Image with Fixed Ratio

From: ImageAnalyst

Date: 27 Sep, 2010 10:12:52

Message: 2 of 6

1. Use imresize().
2. Use padarray().

Subject: Crop Image with Fixed Ratio

From: Nehal

Date: 27 Sep, 2010 14:48:04

Message: 3 of 6

ImageAnalyst <imageanalyst@mailinator.com> wrote in message <048b6df1-f500-401f-9213-fc646bb9e825@26g2000yqv.googlegroups.com>...
> 1. Use imresize().
> 2. Use padarray().

I have almost 1500 images. And the dimensions are not same in all the images. So I need to run a loop and resize the images first. But how can I do that..?

Subject: Crop Image with Fixed Ratio

From: Nehal

Date: 27 Sep, 2010 14:50:20

Message: 4 of 6

ImageAnalyst <imageanalyst@mailinator.com> wrote in message <048b6df1-f500-401f-9213-fc646bb9e825@26g2000yqv.googlegroups.com>...
> 1. Use imresize().
> 2. Use padarray().

if i just use imresize (imageArray, [mrows ncols]);

it stretches and squeezes the object in the image.. that's the thing I am aware of.. I do not want the image to be resized like that...

Subject: Crop Image with Fixed Ratio

From: ImageAnalyst

Date: 27 Sep, 2010 15:20:31

Message: 5 of 6

Sorry - I meant imcrop(). That will not change the aspect ratio of
the images, then you can add background padding with padarray.

Subject: Crop Image with Fixed Ratio

From: pratibha rane

Date: 9 Apr, 2013 10:48:06

Message: 6 of 6

how shadow, variance effect is removed from the given image to get exact binary image?

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us