Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Reshape array for 256 by 256 matrix showing 16 by 256

Asked by sudipta on 27 Jun 2013

I have 65536 real data points saved from an image. I have used reshape command to make square matrix. But result I am getting is 16 by 256 . Why is it so? Can I reconstruct the image ??

This is the .txt file http://m.uploadedit.com/b017/1372387722318.txt and code i used is

 a = load('fname.txt');
 y=reshape (a,256,256)

but instead of 256 by 256 it is showing 16 by 256

5 Comments

Chong on 28 Jun 2013

Hi sudipta, I have tried your code using 1372387722318.txt :

length(a) returned 65536 while size(y) also returned 256 256 on my side.

Just being curious, could there be another fname.txt or 1372387722318.txt file in your working directory?

sudipta on 28 Jun 2013

Hi, For me it is coming as Column 1-16 in 256 lines, each line with 16 value then column 17-32 again 16 by 256 ....why so?

Giorgospapanas on 28 Jun 2013

Hi Sudipta! Have you tried to use the command double before resizing? As far as I understood you would like to resize your image.

1) So, from the beginning, first you can get the file:

[Get_file,Get_pathname]=uigetfile;

2) Then it is very important to read and double it:

Temp_Image=double(dicomread(fullfile(Get_pathname,Get_file)));

3) At the end you can resize it:

 Image=imresize(Temp_Image,resizefactor);

I think the most important thing is to double the image before any further post-processing step.

I hope that helps,

Giorgos

sudipta

4 Answers

Answer by Ahmed A. Selman on 28 Jun 2013
Accepted answer

Dear sudipta,

I have downloaded your data file, and went like

a=load('1372387722318.txt');
y=reshape (a,256,256);
whos 
Name          Size              Bytes  Class     Attributes
a         65536x1              524288  double              
y           256x256            524288  double

and everything is just fine to me. So, the only possible error is that: you have another file with a name (fname.txt) in your directory which is not the same file you uploaded (1372387722318.txt). Check this out and I'm pretty sure you'll have it working.

Regards

0 Comments

Ahmed A. Selman
Answer by Jan Simon on 28 Jun 2013
Edited by Jan Simon on 28 Jun 2013

It is impossible that Matlab's reshape changes the number of elements of the processed array. Therefore I'm convinced, that something completely different went wrong:

  1. You do not read the file your assume to read
  2. "It is showing 16 by 256" does not explain, how you check the size. Perhaps the bug is found in your method to obtain the array size.
  3. You do not use Matlab's reshape but a user-defined function. Check this by:
which reshape -all

0 Comments

Jan Simon
Answer by Anand on 27 Jun 2013

This is what you should do for an image with 65536 pixels that you want to make square:

nelem = numel(A);
side  = sqrt(nelem);
Areshaped = reshape(A,side,side);

1 Comment

sudipta on 28 Jun 2013

GIvimg same result. I have upodated my question with the data and code

Anand
Answer by David Sanchez on 28 Jun 2013

To reshape/resize an image, use:

imresize

Type:

help imresize

Or

doc imresize

for all the information needed to handle the issue.

0 Comments

David Sanchez

Contact us