Hi, I have a question here.
Take for example an image of size n by m. What I want is to split the images into 4 similar quadrants as follows: http://www.flickr.com/photos/jokerzy89/5859808219/ Next, I want to swap the following. (1)A and C (2) B and D, then display the final result as a new image.
Can someone please help? Thank you!

4 Kommentare

Jason
Jason am 22 Jun. 2011
My guess is that first you need to read the size of the image, then proceed to define the four quadrants. Something like this:
A = image(1:n/2, 1:m/2);
B = image(1:n/2, m/2:m);
C = image(n/2:n, 1:m/2);
D = image(n/2:n, m/2:m);
Am I right?
Sean de Wolski
Sean de Wolski am 22 Jun. 2011
A is B in the above. It's not right because row/cols: n/2 , m/2 will each appear twice and what would happen if you had an off image say: 255x255
255/2 = ? - a non-integer index.
Jason
Jason am 22 Jun. 2011
Thank you, that is why the floor function comes into picture.
Sean de Wolski
Sean de Wolski am 22 Jun. 2011
yes, you could also use ceil.

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Sean de Wolski
Sean de Wolski am 22 Jun. 2011

2 Stimmen

swap1324 = @(x)([x((floor(size(x,1)/2)+1):end,(floor(size(x,2)/2)+1):end) x((floor(size(x,1)/2)+1):end,1:floor(size(x,2)/2)); x(1:floor(size(x,1)/2),(floor(size(x,1)/2)+1):end) x(1:floor(size(x,1)/2),1:floor(size(x,2)/2))]);
I = imread('cameraman.tif'); %sample image
I2 = swap1324(I);
imtool(I2)
Obviously the above should be broken down into it's own function that doesn't have to repeat the function floor(size(stuff))) over and over again.

1 Kommentar

Jason
Jason am 22 Jun. 2011
That was fast, and it was exactly what I needed, thank you, Sean!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Convert Image Type finden Sie in Hilfe-Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by