1 Replies - 12937 Views - Last Post: 11 April 2008 - 01:58 AM Rate Topic: -----

#1 Tavisha  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 42
  • Joined: 28-February 08

MATLAB CODE FOR Reading a RAW format gray scale image from disk

Posted 14 March 2008 - 10:29 AM

Hi All

I have this code here

it is for Reading a RAW format gray scale image

[code]

fid = fopen(filename,'rb');
if (fid==1)
error('Cannot open image file...press CTRL-C to exit ');pause
end
temp = fread(fid, nSize, 'uchar');
fclose(fid);
result = reshape(temp, [nRow nColumn])';

Where
input: filename : input file
nSize : size of the output image
nRow : row of the output image
nColumn : column of the output image
output: result : output data in matrix format

###

My Questions are:
1. Filename can be .bmp/.jpg right ? I am using lena ( 128X128)
2. if I give nsize as 128 then what should be filled in [ nrow ncolumn] matrix?
it is giving me errors saying " elements should be same "


PLEASE HELP !!!!

Is This A Good Question/Topic? 0
  • +

Replies To: MATLAB CODE FOR Reading a RAW format gray scale image from disk

#2 Predictor  Icon User is offline

  • D.I.C Head

Reputation: 12
  • View blog
  • Posts: 90
  • Joined: 20-September 07

Re: MATLAB CODE FOR Reading a RAW format gray scale image from disk

Posted 11 April 2008 - 01:58 AM

The answer to your first question is: No, the files cannot be JPEG or BMP format. The code you provided reads in a series of bytes, which I presume are luminance ("grayscale") values, then re-shapes them into a 2-D array. Formats like JPEG and BMP are much more complicated than this. The good news is that MATLAB can read those as well. Try 'help imread'.

The answer to your second question is that the vector [ nrow ncolumn] is supposed to contain the number of rows and the number of columns. In the case you described, that would be [128 128].


-Will
Data Mining in MATLAB

View PostTavisha, on 14 Mar, 2008 - 10:29 AM, said:

Hi All

I have this code here

it is for Reading a RAW format gray scale image

[code]

fid = fopen(filename,'rb');
if (fid==1)
error('Cannot open image file...press CTRL-C to exit ');pause
end
temp = fread(fid, nSize, 'uchar');
fclose(fid);
result = reshape(temp, [nRow nColumn])';

Where
input: filename : input file
nSize : size of the output image
nRow : row of the output image
nColumn : column of the output image
output: result : output data in matrix format

###

My Questions are:
1. Filename can be .bmp/.jpg right ? I am using lena ( 128X128)
2. if I give nsize as 128 then what should be filled in [ nrow ncolumn] matrix?
it is giving me errors saying " elements should be same "


PLEASE HELP !!!!

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1