Problem with imresize function.

6 visualizzazioni (ultimi 30 giorni)
Anish Surana
Anish Surana il 23 Apr 2012
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.

Risposta accettata

Image Analyst
Image Analyst il 23 Apr 2012
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 Commento
Anish Surana
Anish Surana il 23 Apr 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...

Accedi per commentare.

Più risposte (2)

Jan
Jan il 23 Apr 2012
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 Commenti
Anish Surana
Anish Surana il 23 Apr 2012
Thanx for the answer.It works well.However,having these many zeroes in y would be too redundant for my purpose.
Jan
Jan il 23 Apr 2012
Then, of course, you can omit the zeros and use this:
y = x(:).'

Accedi per commentare.


Geoff
Geoff il 23 Apr 2012
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 Commento
Anish Surana
Anish Surana il 23 Apr 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.

Accedi per commentare.

Categorie

Scopri di più su Language Fundamentals in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by