basics (Spring 2013)
Contents
iminfo
info = imfinfo(filename) returns a structure whose fields contain information about an image in a graphics file. filename is a string that specifies the name of the graphics file
filename = '2013_0115_163116AA.JPG'; info = imfinfo(filename); disp(info) % which leads us to enter: info.DigitalCamera info.ExifThumbnail
Filename: [1x66 char]
FileModDate: '16-Jan-2013 22:31:05'
FileSize: 607096
Format: 'jpg'
FormatVersion: ''
Width: 2048
Height: 1536
BitDepth: 24
ColorType: 'truecolor'
FormatSignature: ''
NumberOfSamples: 3
CodingMethod: 'Huffman'
CodingProcess: 'Sequential'
Comment: {}
Make: 'FUJIFILM'
Model: 'FinePix6900ZOOM'
Orientation: 1
XResolution: 72
YResolution: 72
ResolutionUnit: 'Inch'
Software: 'Digital Camera FinePix6900ZOOM Ver1.00'
DateTime: '2013:01:15 16:31:16'
YCbCrPositioning: 'Co-sited'
Copyright: ' '
DigitalCamera: [1x1 struct]
ExifThumbnail: [1x1 struct]
ans =
FNumber: 2.8000
ExposureProgram: 'Normal program'
ISOSpeedRatings: 100
ExifVersion: [4x1 double]
DateTimeOriginal: '2013:01:15 16:31:16'
DateTimeDigitized: '2013:01:15 16:31:16'
ComponentsConfiguration: 'YCbCr'
CompressedBitsPerPixel: 1.5000
ShutterSpeedValue: 6
ApertureValue: 3
BrightnessValue: 3.1100
ExposureBiasValue: 0
MaxApertureValue: 3
MeteringMode: 'Pattern'
Flash: [1x131 char]
FocalLength: 9.7000
MakerNote: [238x1 double]
FlashpixVersion: [4x1 double]
ColorSpace: 'sRGB'
CPixelXDimension: 2048
CPixelYDimension: 1536
InteroperabilityIFD: [1x1 struct]
FocalPlaneXResolution: 2678
FocalPlaneYResolution: 2674
FocalPlaneResolutionUnit: 3
SensingMethod: 'One-chip color area sensor'
FileSource: 'DSC'
SceneType: 'A directly photographed image'
ans =
Filename: [1x66 char]
FileModDate: '16-Jan-2013 22:31:05'
FileSize: 607096
Format: 'jpg'
FormatVersion: []
Width: 0
Height: 0
BitDepth: 0
ColorType: -1
FormatSignature: []
Compression: 'OJPEG'
Make: []
Model: []
Orientation: 1
XResolution: 72
YResolution: 72
ResolutionUnit: 'Inch'
Software: []
DateTime: []
JPEGInterchangeFormat: 1102
JPEGInterchangeFormatLength: 9225
YCbCrPositioning: 'Co-sited'
Copyright: []
DigitalCamera: []
imread
A = imread(filename) reads a grayscale or color image from the file specified by the string filename.
rgb = imread(filename);
whos rgb
Name Size Bytes Class Attributes rgb 1536x2048x3 9437184 uint8
imshow
imshow(RGB) displays the truecolor image RGB.
small = imresize(rgb,0.3); imshow(small);
imcrop
I = imcrop creates an interactive Crop Image tool associated with the image displayed in the current figure, called the target image. The Crop Image tool is a moveable, resizable rectangle that you can position interactively using the mouse.
imshow(rgb); [out rect] = imcrop; rect
Warning: Image is too big to fit on screen; displaying at 50% rect = 657.5100 497.5100 707.9800 461.9800
imwrite
imwrite(A,filename) writes the image A to the file specified by filename in the format specified the file extension.
imwrite(out,'cropped_target.jpg');
imshow(out);
I = rgb2gray(RGB) converts the truecolor image RGB to a grayscale intensity image I. rgb2gray converts RGB images to grayscale by eliminating the hue and saturation information while retaining the luminance.
g = rgb2gray(out); imshow(g);
imhist(I) displays a histogram for the image I above a grayscale colorbar. The number of bins in the histogram is specified by the image type. If I is a grayscale image, imhist uses a default value of 256 bins.
imhist(g);
level = graythresh(I) computes a global threshold (level) that can be used to convert an intensity image to a binary image with im2bw. level is a normalized intensity value that lies in the range [0, 1].
%The graythresh function uses Otsu's method, which chooses the threshold % to minimize the intraclass variance of the black and white pixels. level = graythresh(g); fprintf('threshold %g\n',level); BW = im2bw(g,level); imshow(BW);
threshold 0.521569
CC = bwconncomp(BW) returns the connected components CC found in BW. The binary image BW can have any dimension. CC is a structure with four fields.
CC = bwconncomp(~BW); disp(CC)
Connectivity: 8
ImageSize: [462 708]
NumObjects: 21
PixelIdxList: {1x21 cell}
L = labelmatrix(CC) creates a label matrix from the connected components structure CC returned by bwconncomp. The size of L is CC.ImageSize. The elements of L are integer values greater than or equal to 0.
L = labelmatrix(CC);
RGB = label2rgb(L) converts a label matrix into an RGB color image for the purpose of visualizing the labeled regions.
RGB = label2rgb(L); imshow(RGB);
show "inbetween" values;
msk1 = g>100; msk2 = g<150; imshow(msk1.*msk2);