Saturday, 25 June 2011

Repositioning an image

Re-positioning an image in matlab may seem confusing at first but is actually very simple.

The algorithm is as follows:

1) Read the image into an array A using imread or other inbuilt reading functions.
2) If you want to shift to the right by 5 pixels, add 5 columns of 0's to your array A and store that in array B.
3) Write this into another array C of size same as array A.
4) 4 columns of image information will be lost and you will find your picture moved by 5 pixels.

If you want to shift the image to the left, it might be a tad trickier.

1) Read the image into an array A using imread or other inbuilt functions.
2) If you want to shift to the left by 5 pixels, write the elements of array A after 5 columns(in the for loop start the column iterations from 5 instead of 1) and store this in a pre-initialized array of zeros. This will add columns of zeros(dark) to the left of your image.. and the image will appear shifted to the left when it is displayed.

An important thing to note is that before using any of these techniques, we should add zeros all around the image so that no image information is lost.




No comments:

Post a Comment