(Read matlab basics first )
IMAGES AS MATRICES :
Images in image processing toolbox are defined as matrices with each element in matrix representing a pixel
f(r,c) is the representation of the matrix where r is rows and c is columns
the origin is 1,1
Note that f(1,2) represents the pixel of 1st row and 2nd column
imread('filename')
f= imread('rajat.jpg');
The semicolon in the end is used to suppress output if the semicolon is not entered it displays the output.
This file rajat.jpg must be in the working directory otherwise u have to give the full file path.(f=imread('c:\mydocument\supertramp\rajat.jpg')
Read More>>
size(f)
ans =
1024 1024
this specifies the image height and width in pixels
[m.n] = size(f);
this returns the no. of rows and column in the image matrix
DISPLAYING IMAGES:
imshow(f, g)
here f is the image array and g is the intensity
g can take many format
if g is omitted matlab defaults it to 256 levels
imshow(f,[low high])
this displays all values less than or equal to low as black and all values greater than or equal to high as white..the values in between r displayed as intermediate intensity values using the default number of levels.
imshow(f,[ ])
this sets the value of low to minimum of the matrix and high to the maximum
pixval
when u type pixval it shows the cursor on the last image displayed.Clicking the X button on teh cursor window turns it off.
pixval command is used to frequently to dispaly the intensity values of individual pixels interactively. as teh cursor moves over the image the coordinates of the cursor position and the corresponding intensity values are displayed that appers below the color window , with color images red,blue,green values are also displayed .
To display 2 figure simultaneously use figure function like this
imshow(f), figure ,imshow(g)
remember g show contain an image matrix
WRITITNG IMAGES:
to write images to disk use
imwrite(f,'filename')
file name shuld contain the extension of the file
and if u will nt give the path with the file name matlab will save this image to current working directory
imwrite has many syntax
for ex:
imwrite(f,'c:\mydocument\supertramp\rajat.jpg','quality',25)
here 25 is the jpeg compression value the lower the no. the higher the degradaiton
imfinfo filename
this displayes all the information about the image
for exmple
>> imfinfo 'rajat.jpg
ans =
Filename: 'rajat.jpg'
FileModDate: '05-Oct-2009 06:47:00'
FileSize: 1982
Format: 'jpg'
FormatVersion: ''
Width: 133
Height: 100
BitDepth: 24
ColorType: 'truecolor'
FormatSignature: ''
NumberOfSamples: 3
CodingMethod: 'Huffman'
CodingProcess: 'Sequential'
Comment: {}
now , u can store all of this information into a variable
like this
k=imfinfo('rajat.jpg');
this k is now a structure variable and it has all the fields mentioned above like filename , filesize , height
u can retrieve alll the information like this
this is the program to know the compression ration
EXAMPLE::
k=imfinfo('rajat.jpg');
imagebytes=k.Width*k.Height*k.BitDepth/8;
(we divided the product with 8 because this information was it bits)
compressed_bytes=k.FileSize;
compressed_ratio=imagebytes/compressed_bytes
ans
compressed_ratio =
20.1312
2 things u shud notice
Use semicolon after every line because we don't want output after every line. Just don't use semicolon in the end because we want output in the end .
remember that matlab is case sensitive so if u will write k.width it will not work and will give error use k.Width
to be continued.....
0 comments:
Post a Comment