Welcome to Dream.In.Code
Getting Help is Easy!

Join 86,382 Programmers. There are 1,401 online right now! Ask your question and get quick answers from Dream.In.Code experts. Join the #1 programming help community on the internet! Registration is fast and FREE... Join Now!

Chat LIVE With a Expert
Powered by LivePerson.com

Register to Make This Box Go Away!

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

 
Reply to this topicStart new topic

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

Tavisha
post 14 Mar, 2008 - 10:29 AM
Post #1


New D.I.C Head

*
Joined: 28 Feb, 2008
Posts: 42



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 !!!!
User is offlineProfile CardPM
Go to the top of the page
+Quote Post


Predictor
post 11 Apr, 2008 - 01:58 AM
Post #2


New D.I.C Head

*
Joined: 20 Sep, 2007
Posts: 19

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

QUOTE(Tavisha @ 14 Mar, 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 !!!!

User is offlineProfile CardPM
Go to the top of the page
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 5/17/08 03:37AM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month