MATLAB
MATLAB
Initializing a matrix:
Example: my_matrix = [1 2 3; 4 5 6; 7 8 9];
A=
1 2
3 4
I=
1
2
3
Flow Control
imwrite(I, ‘newim.jpg’)
Image Display
image - create and display image object
imagesc - scale and display as image
imshow - display image
colorbar - display colorbar
getimage- get image data from axes
truesize - adjust display size of image
zoom - zoom in and zoom out of 2D plot
Image Conversion
gray2ind - intensity image to index image
im2bw - image to binary
im2double - image to double precision
im2uint8 - image to 8-bit unsigned integers
im2uint16 - image to 16-bit unsigned integers
ind2gray - indexed image to intensity image
mat2gray - matrix to intensity image
rgb2gray - RGB image to grayscale
rgb2ind - RGB image to indexed image
Geometric Operations
Image resizing: imresize(I,[x y],’method’). Method is
bilinear, bicubic or nearest neighbours.
Image rotation: imrotate(I,angle,’method’) method is
same as before. Zero padding in the rotated image.
Image cropping: J=imcrop;
Neighbourhood Processing
To speed up neighbourhood processing transform every
neighbourhood to column vector and perform vector
operations.
17
Transforms
Fourier and inverse Fourier transform:
impixel returns the data value for a selected set of pixels. The
set can be pointed by the mouse or by coordinates.
19
Edge detection:
edge(I,’sobel’);
edge(I,’canny’);
Or by fspecial(‘sobel’) and conv2.
Image Enhancement:
Histogram stretching:
imadjust(I,[low high],[bottom top]);
Gamma correction:
imadjust(I,[],[],gamma_coef);
Histogram Equalization
histeq(I)
20
Noise removal
To add noise to an image:
Median filtering:
F=medfilt(J,[3 3]);
21
Morphological Operations
Dilation : imdilate()
Erosion: imerode()
Closing: imclose()
Opening: imopen()
22
Color
The available colorspaces:
RGB, NTSC (US televisions), YCbCr (Digital video), HSV.
Transformations between the spaces:
rgb2ntsc, hsv2rgb, …
23
Questions?