Problem with imresize function.

조회 수: 6 (최근 30일)
Anish Surana
Anish Surana 2012년 4월 23일
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.

채택된 답변

Image Analyst
Image Analyst 2012년 4월 23일
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
Anish Surana
Anish Surana 2012년 4월 23일
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...

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

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

댓글을 달려면 로그인하십시오.


Geoff
Geoff 2012년 4월 23일
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
Anish Surana
Anish Surana 2012년 4월 23일
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Language Fundamentals에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by