CONVERT/RESHAPE TO 2D

1 view (last 30 days)
LOKESH
LOKESH on 4 Feb 2012
Edited: Matt J on 29 Sep 2013
I have reshaped my 2d nxn image B1 to 1d[row-wise] using
B2 = reshape(B1.',1,[]),
then i applied the transformation with only one "i" loop: XX,YY &ZZ are parameters found by the methods.
for i=1:((M^2)/3-1)
Kx(i)=uint8(mod((abs(XX(i))-floor(abs(XX(i))))*10^14,256));
Ky(i)=uint8(mod((abs(YY(i))-floor(abs(YY(i))))*10^14,256));
Kz(i)=uint8(mod((abs(ZZ(i))-floor(abs(ZZ(i))))*10^14,256));
end;
for i=1:((M^2)/3-1)
C1(3*(i-1)+1)=mod(bitxor(B2(3*(i-1)+1),Kx(i)),256);
C1(3*(i-1)+2)=mod(bitxor(B2(3*(i-1)+2),Ky(i)),256);
C1(3*(i-1)+3)=mod(bitxor(B2(3*(i-1)+3),Kz(i)),256);
end;
Now As i display this image i get a line & giving error "Image is too big ,displaying only 2%". How can i get this modified image to 2d nxn image.
Her i use Greyscle image
image size is 256x256
The code works fine with 183x183 size image

Answers (1)

Walter Roberson
Walter Roberson on 4 Feb 2012
If M is 256, then your C1 cannot be reshaped to a 256 x 256 image.
Your line
for i = 1 : M^2/3 - 1
is equivalent to
for i = 1 : floor(M^2/3 - 1)
and for each "i" value, 3 entries in C3 are created, leading to a total of 3 * floor(M^2/3 - 1) entries. The only time the floor() will not be truncating a fraction is if M^2 is divisible by 3, which occurs only if M is divisible by 3. And 256 is not. It turns out that if M is an integer that is not divisible by 3 then 3 * floor(M^2/3) will come out exactly 1 short of M^2 (and 4 short if you keep the "-1").
I think you will also find that you should not be subtracting 1 from the M^2/3 -- you already subtract the 1 in the indexing by "i".
  2 Comments
LOKESH
LOKESH on 4 Feb 2012
I found that is the image size is not divisible by 3,it gives me error.But if I remove -1,I do not get error but i get only a single line as image and If I use reshape in that I get error[for reshaping the matrix to 2D] :
Error using ==> reshape
Product of known dimensions, 256, not divisible into total number
of elements, 65535.
Error in ==> rk4_CHEN at 197
C2 = reshape(C1.',[],M);
Walter Roberson
Walter Roberson on 4 Feb 2012
Like I said, "3 * floor(M^2/3) will come out exactly 1 short of M^2"
256^2 is 65536, one short of that is 65535, and that is the same as the number of elements.
There are values of M for which M^2 - 1 is a prime number and thus could not be reshaped in to _any_ 2D image of any dimensions. You will thus need to figure out whether the code is intended to generate something that can be reshaped in to an image, and you will need to figure out how you want to deal with that possibly-missing 1 element.

Sign in to comment.

Categories

Find more on Images in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!