0
$\begingroup$

I have the pixel data of an image in a 1x256 vector where each cell represents a pixel of a 16x16 image. I have written the following code in Matlab but I am not getting what is expected as an output image. Am I doing something wrong?

vect = [-1.0000,-1.0000,-1.0000,-1.0000,-1.0000,-1.0000,-1.0000,-0.6310,0.8620,-0.1670,-1.0000,-1.0000,-1.0000,-1.0000,-1.0000,-1.0000,-1.0000,-1.0000,-1.0000,-1.0000,-1.0000,-1.0000,-0.9920,0.2970,1.0000,0.3070,-1.0000,-1.0000,-1.0000,-1.0000,-1.0000,-1.0000,-1.0000,-1.0000,-1.0000,-1.0000,-1.0000,-1.0000,-0.4100,1.0000,0.9860,-0.5650,-1.0000,-1.0000,-1.0000,-1.0000,-1.0000,-1.0000,-1.0000,-1.0000,-1.0000,-1.0000,-1.0000,-0.6830,0.8250,1.0000,0.5620,-1.0000,-1.0000,-1.0000,-1.0000,-1.0000,-1.0000,-1.0000,-1.0000,-1.0000,-1.0000,-1.0000,-0.9380,0.5400,1.0000,0.7780,-0.7150,-1.0000,-1.0000,-1.0000,-1.0000,-1.0000,-1.0000,-1.0000,-1.0000,-1.0000,-1.0000,-1.0000,0.1000,1.0000,0.9220,-0.4390,-1.0000,-1.0000,-1.0000,-1.0000,-1.0000,-1.0000,-1.0000,-1.0000,-1.0000,-1.0000,-1.0000,-0.2570,0.9500,1.0000,-0.1620,-1.0000,-1.0000,-1.0000,-0.9870,-0.7140,-0.8320,-1.0000,-1.0000,-1.0000,-1.0000,-1.0000,-0.7970,0.9090,1.0000,0.3000,-0.9610,-1.0000,-1.0000,-0.5500,0.4850,0.9960,0.8670,0.0920,-1.0000,-1.0000,-1.0000,-1.0000,0.2780,1.0000,0.8770,-0.8240,-1.0000,-0.9050,0.1450,0.9770,1.0000,1.0000,1.0000,0.9900,-0.7450,-1.0000,-1.0000,-0.9500,0.8470,1.0000,0.3270,-1.0000,-1.0000,0.3550,1.0000,0.6550,-0.1090,-0.1850,1.0000,0.9880,-0.7230,-1.0000,-1.0000,-0.6300,1.0000,1.0000,0.0680,-0.9250,0.1130,0.9600,0.3080,-0.8840,-1.0000,-0.0750,1.0000,0.6410,-0.9950,-1.0000,-1.0000,-0.6770,1.0000,1.0000,0.7530,0.3410,1.0000,0.7070,-0.9420,-1.0000,-1.0000,0.5450,1.0000,0.0270,-1.0000,-1.0000,-1.0000,-0.9030,0.7920,1.0000,1.0000,1.0000,1.0000,0.5360,0.1840,0.8120,0.8370,0.9780,0.8640,-0.6300,-1.0000,-1.0000,-1.0000,-1.0000,-0.4520,0.8280,1.0000,1.0000,1.0000,1.0000,1.0000,1.0000,1.0000,1.0000,0.1350,-1.0000,-1.0000,-1.0000,-1.0000,-1.0000,-1.0000,-0.4830,0.8130,1.0000,1.0000,1.0000,1.0000,1.0000,1.0000,0.2190,-0.9430,-1.0000,-1.0000,-1.0000,-1.0000,-1.0000,-1.0000,-1.0000,-0.9740,-0.4290,0.3040,0.8230,1.0000,0.4820,-0.4740,-0.9910,-1.0000,-1.0000,-1.0000,-1.0000];

img = zeros(16,16);

for i=1:16
    for j=1:16
        img(i,j) = vect(i+j);
    end
end

imshow(img,[])

Thanks in advance.

$\endgroup$
  • 1
    $\begingroup$ i+j does not take values 1:256. You need something like reshape. $\endgroup$ – MBaz May 21 '18 at 14:48
  • $\begingroup$ Thank you! It worked, please answer the question so I can mark it as the accepted answer. $\endgroup$ – Peter May 21 '18 at 15:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.