Problem with imresize function.

The problem i am facing is that imresize is not a reversible function.For example,if you convert a binary array of size 5x8 to an array of size 1x192 and then convert it back to size of 5x8,the values are not the same.In case,if u use 'bilinear' attribute then it gives back binary values,however,the values don't match.Please guide me how i can overcome the above problem.(Note:its not essential that the above problem be solved using imresize function.)Any help would be appreciated.

 Respuesta aceptada

Image Analyst
Image Analyst el 23 de Abr. de 2012

0 votos

You need to use reshape, to get it linear so that you don't lose any elements, and then use the 'nearest option of imresize. Check out this demo:
% Generate sample binary data.
m = randi(2, [5 8])-1
% Now do what Anish wants to do.
mLinear = reshape(m, [1 numel(m)])
% Now make it 192 elements long, for some reason.
mLinear192 = imresize(mLinear, [1 192], 'nearest')
% Undo the process:
mLinear2 = imresize(mLinear192, [1 numel(m)], 'nearest')
m2 = reshape(mLinear2, [5 8]);
% Subtract to see if we did it correctly;
difference1 = mLinear2 - mLinear % Check stage 1.
difference2 = m2 - m % Check final stage
Why do you want to do this anyway? What does this do that you can't do when it's left in its 2D form?

1 comentario

Anish Surana
Anish Surana el 23 de Abr. de 2012
Thanx a lot...it works the way i want it to be.I need it for my steganography project(DWT with HVS) where i am supposed to have a row vector which is later to be converted into three matrices for embedding purpose...

Iniciar sesión para comentar.

Más respuestas (2)

Jan
Jan el 23 de Abr. de 2012

0 votos

Resizing an image until it has a single row only cannot be reversible. Reshaping seems to be more useful, if the problem is not restricted to imresize:
x = rand(5, 8);
y = zeros(1, 192);
y(1:numel(x)) = x(:)';
And backwards:
x2 = reshape(y(1:(5 * 8)), 5, 8);

2 comentarios

Anish Surana
Anish Surana el 23 de Abr. de 2012
Thanx for the answer.It works well.However,having these many zeroes in y would be too redundant for my purpose.
Jan
Jan el 23 de Abr. de 2012
Then, of course, you can omit the zeros and use this:
y = x(:).'

Iniciar sesión para comentar.

Geoff
Geoff el 23 de Abr. de 2012

0 votos

The upscale and subsequent downscale of 8 > 192 > 8 should be fine, but I don't know how you expect resizing from 5 > 1 > 5 is going to give you back the same information. When you collapse 5 lines down to 1, you lose all the information in those lines. You cannot scale it back up to 5 and expect your original data to come back out.
Think of this:
R = rand(5,1);
M = mean(R);
How do you recover R using only M?

1 comentario

Anish Surana
Anish Surana el 23 de Abr. de 2012
Thanx for the answer...what i was concerned was the elements(in the same specific order like a bit stream) and not the rows and columns.

Iniciar sesión para comentar.

Categorías

Más información sobre Language Fundamentals en Centro de ayuda y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by