Lecture 4 Writing Images and Data Classes
Lecture 4 Writing Images and Data Classes
Qadri Hamarsheh
Writing images
1
Dr. Qadri Hamarsheh
>> subplot 233; imshow(f5); title('Image with q=5');
>> subplot 234; imshow(f15); title('Image with q=15');
>> subplot 235; imshow(f25); title('Image with q=25');
>> subplot 236; imshow(f50); title('Image with q=50');
Notes about the program
Quality value Remark
q= 5 or q=0 quite visible(not suitable)
q= 15 false contouring visible
q= 25 acceptable solution with some error
Some of the image/ graphics formats supported by imread and imwrite,
imwrite starting with
matlab 6.5.
TIFF, JPEG, GIF, BMP, PNG, XWD
o GIF is supported by imread,
imread but not by imwrite
imwrite.
write
imfinfo function:
• The imfinfo
imfinfo function returns information about the image file, such as size, width,
height, the compression achieved and other image file details.
Syntax:
imfinfo
imfinfo filename
>> imfinfo football25.jpg
The ouput of the imfinfo function
Filename: [1x93 char]
FileModDate: '27-Feb-2012 22:59:15'
FileSize: 5002
Format: 'jpg'
FormatVersion: ''
Width: 320
Height: 256
BitDepth: 24
ColorType: 'truecolor'
FormatSignature: ''
NumberOfSamples: 3
CodingMethod: 'Huffman'
CodingProcess: 'Sequential'
Comment: {}
• From the output of this command, we remark that:
File size (in bytes): the number of bytes in the original image is computed (original size):
2
Dr. Qadri Hamarsheh
• The information fields displayed by imfinfo can be captured into a structure variable
that can be used for computations.
>> k= imfinfo ('football25.jpg');
k – Structure name; k- contains fields, that can be accessed by dot operator.
For example, the image height and width are stored in structure fields k.Heigh and
k.Wid
.Width
idth.
th
Example using structure:
• Compute the compression ratio for football25.jpg:
>> K= imfinfo ('football25.jpg');
>> image_size = K.Width * K.Height * K.BitDepth/8;
>> compression_ratio = image_size/ k.FileSize
Compression_ratio = 49.1323
3
Dr. Qadri Hamarsheh
Data Classes
• The data classes supported by matlab and IPT for representing pixel values as in the
following table:-
Bytes/
Class
Type Description Range per
Name
element
double Floating-
Floating-point numbers (−ૡ −ૡ ) 8
uint8 Unsigned 8-
8-bit integers (0-
(0-255) 1
• The frequently data classes that encountered in image processing are double, uint8
and logical.
• Logical arrays are created by using function logical or by using relational
operators.
operators