当前位置:文档之家› matlab 图像处理

matlab 图像处理


Read an Image
Read in an image Validates the graphic format
(bmp, hdf, jpeg, pcx, png, tiff, xwd)
Store it in an array
clear, close all I = imread(‘pout.tif`); [X, map] = imread(‘pout.tif’);
graindata(51).Centroid
{155.3953 102.1791}
Create a vector which holds just one property for each object
allgrains = [graindata.Area];
whos
Statistical Properties of Objects
I = imread(‘moon.tif’); J = immultiply(I, 1.2); imshow(I); figure, imshow(J)
Multiplying Images (cont.)
Dividing Images (Ratioing)
I = imread(‘rice.tif’); background = imopen(I, strel(‘disk’, 15)); Ip = imdivide(I, background); imshow(Ip, [])
Negative valueages (cont.)
Multiplying Images
Scaling: multiply by a constant
(brightens >1, darkens <1)
Preserves relative contrast
I2 = histeq(I); figure, imshow(I2) figure, imhist(I2)
Histogram Equalization (cont.)
Histogram Equalization (cont.)
Write the Image
Validates the extension Writes the image to disk
I3 = imadjust(I2, stretchlim(I2), [0 1]); figure, imshow(I3)
Apply Thresholding to the Image
Create a binary thresholded image
1. Compute a threshold to convert the intensity image to binary
Display an Image
imshow(I)
Check the Image in Memory
< Name, Size, Bytes, Class >
whos
Name Size
Bytes Class
ans 291x240 69840 uint8 array
Grand total is 69840 elements using 69840 bytes
imwrite(I2, ’pout2.png’); imwrite(I2, ‘pout2.png’, ‘BitDepth’, 4);
Morphological Opening
Remove objects that cannot completely contain a structuring element
[labeled, numObjects] = bwlabel(bw, 4);
numObjects max(labeled(:))
{= 80}
Select and Display Pixels in a Region
Interactive selection
grain = imcrop(labeled)
Estimate background illumination
clear, close all I = imread(‘rice.tif’); imshow(I) background = imopen(I, strel(‘disk’, 15)); imshow(background)
Morphological Opening (cont.)
Labeling Connected Components
Determine the number of objects in the image
Accuracy
(size of objects, approximated background, connectivity parameter, touching objects)
I = imread(‘rice.tif’); J = imread(‘cameraman.tif’); K = imadd(I, J); imshow(K)
Brighten an image results saturation
RGB = imread(‘flowers.tif’); RGB2 = imadd(RGB, 50); subplot(1, 2, 1); imshow(RGB); subplot(1, 2, 2); imshow(RGB2);
max(allgrains)
{ 695 }
Return the component label of a grain size
biggrain = find(allgrains == 695) { 68 }
Mean grain size
mean(allgrains)
{ 249 }
Histogram (#bins)
Colormap creation function
RGB_label = label2rgb(labeled, @spring, ‘c’, ‘shuffle’);
imshow(RGB_label); rect = [15 25 10 10]; roi = imcrop(labeled, rect)
Same size, #planes, colormap Store separate images into one multiframe
array
A = cat(4, A1, A2, A3, A4, A5)
Extract frames from a multiframe array
FRM3 = MULTI(:, :, :, 3)
Linear combination only truncates the final result
K = imlincomb(.5, I, .5, I2);
Dividing Images (cont.)
Coordinate Systems
Pixel Coordinates
Discrete unit (integer) (r, c) = (1, 1)
Subtract Images
Create a more uniform background
I2 = imsubtract(I, background); figure, imshow(I2)
Adjust the Image Contrast
stretchlim computes [low hight] to be mapped into [bottom top]
uint8 uint16 double
[0, 255] [0, 65535] [0, 1]
Histogram Equalization
Histogram: distribution of intensities
figure, imhist(I)
Equalize Image (contrast)
Adding Images (cont.)
Adding Images (cont.)
Subtracting Images
Background of a scene
rice = imread(‘rice.tif’); background = imopen(rice, strel(‘disk’, 15)); rice2 = imsubtract(rice, background); imshow(rice), figure, imshow(rice2);
Data matrix (uint8, uint16, double) Colormap matrix (m x 3 array of double [0 1])
Intensity (black = 0, white = ) Binary (0, 1)
B = logical(uint8(round(A))); (logical flag on) B = +A; (logical flag off)
MATLAB
Image Processing Toolbox
Introduction
Collection of functions (MATLAB files) that supports a wide range of image processing operations
Documentation
double im2double (automatic rescale and offsetting) RGB2 = im2uint8(RGB1); im2uint16 imapprox (reduce number of colors: indexed images)
Image Types
Index
Object Properties
Measure object or region properties
相关主题