matlab图像分割
合集下载
相关主题
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
uint8 17-15 x 17-16 y
single
277
Visible Red Band
Near Infrared Band
17-15
17-16
ndvi = (NIR - red) ./ (NIR + red);% figure; subplot(121) imshow(ndvi,'DisplayRange',[-1 1])% title('Normalized Difference Vegetation Index') threshold = 0.4;% q = (ndvi > threshold);% 100 * numel(NIR(q(:))) / numel(NIR) subplot(122); imshow(q)% title('NDVI with Threshold Applied') h = figure; p = get(h,'Position'); set(h,'Position',[p(1,1:3),p(3)/2]) subplot(1,2,1); plot(red, NIR, '+b')% hold on plot(red(q(:)), NIR(q(:)), 'g+')% set(gca, 'XLim', [0 1], 'YLim', [0 1]) axis square xlabel('red level'); ylabel('NIR level') title('NIR vs. Red Scatter Plot') subplot(1,2,2); imshow(q)% set(h,'Colormap',[0 0 1; 0 1 0]) title('NDVI with Threshold Applied')
ndvi
278
NIR
red
NIR red NIR red
nvdi
single [-1, 1]
double 17-17
17-17
Normalized Difference Vegetation Index
NDVI with Threshold Applied
17-17
17-18
17-18
17.5 分水岭分割算法
279
例 17-6
fspecial imfilter watershed label2rgb imopen imclose imreconstruct imcomplement imregionalmax bwareaopen graythresh imimposemin
rgb = imread('pears.png');% I = rgb2gray(rgb);% figure; subplot(121)% imshow(I) text(732,501,'Image courtesy of Corel',... 'FontSize',7,'HorizontalAlignment','right') hy = fspecial('sobel');%sobel hx = hy'; Iy = imfilter(double(I), hy, 'replicate');% y Ix = imfilter(double(I), hx, 'replicate');% x gradmag = sqrt(Ix.^2 + Iy.^2);% subplot(122); imshow(gradmag,[]), % title('Gradient magnitude (gradmag)')
17-20
Watershed transform of gradient magnitude (Lrgb)
Watershed transform of gradient magnitude (Lrgb)
17-20
se = strel('disk', 20);% Io = imopen(I, se);% figure; subplot(121) imshow(Io), % title('Opening (Io)') Ie = imerode(I, se);% Iobr = imreconstruct(Ie, I);% subplot(122); imshow(Iobr), % title('Opening-by-reconstruction (Iobr)') Ioc = imclose(Io, se);% figure; subplot(121) imshow(Ioc), % title('Opening-closing (Ioc)') Iobrd = imdilate(Iobr, se);% Iobrcbr = imreconstruct(imcomplement(Iobrd), ... imcomplement(Iobr));% Iobrcbr = imcomplement(Iobrcbr);% subplot(122); imshow(Iobrcbr), % title('Opening-closing by reconstruction (Iobrcbr)') fgm = imregionalmax(Iobrcbr);% figure; imshow(fgm), % title('Regional maxima of opening-closing by reconstruction (fgm)') I2 = I;
17-19
Gradient magnitude (gradmag)
Image courtesy of Corel
17-19
sobel
sobel 17-19
280
L = watershed(gradmag);% Lrgb = label2rgb(L);% figure; imshow(Lrgb), % title('Watershed transform of gradient magnitude (Lrgb)')
17-14
MATLAB decorrstretch 17-14
NIR = im2single(CIR(:,:,1));% red = im2single(CIR(:,:,2));% figure; subplot(121) imshow(red)% title('Visible Red Band'); subplot(122) imshow(NIR)% title('Near Infrared Band'); figure plot(red, NIR, '+b')% set(gca, 'XLim', [0 1], 'XTick', 0:0.2:1,... 'YLim', [0 1], 'YTick', 0:0.2:1); axis square; xlabel('red level'); ylabel('NIR level'); title('NIR vs. Red Scatter Plot')
第
17 章
MATLAB 图像分割实战
17.3 检测交通视频中的汽车目标
例 17-4
mmreader imextendedmax imopen
implay bwareaopen
trafficObj = mmreader('traffic.avi');% get(trafficObj)% implay('traffic.avi');%
274
noSmallStructures = bwareaopen(noSmallStructures, 150);% L = bwlabel(noSmallStructures);% taggedCars(:,:,:,k) = singleFrame; if any(L(:)) stats = regionprops(L, {'centroid','area'});% areaArray = [stats.Area];% [junk,idx] = max(areaArray);% c = stats(idx).Centroid;% c = floor(fliplr(c)); width = 2; row = c(1)-width:c(1)+width;% col = c(2)-width:c(2)+width; taggedCars(row,col,1,k) = 255;% taggedCars(row,col,2,k) = 0; taggedCars(row,col,3,k) = 0; end end frameRate = get(trafficObj,'FrameRate'); implay(taggedCars,frameRate);%
get
General Properties: Duration = 8.0000 Name = traffic.avi Path = F:\MATLAB\R2008b\toolbox\images\imdemos Tag = Type = mmreader UserData = [] Video Properties: BitsPerPixel = 24 FrameRate = 15.0000 Height = 120 wk.baidu.comumberOfFrames = 120 VideoFormat = RGB24 Width = 160
mmreader AVI MPG AVI implay MPEG WMV ASF 17-11 ASX
mmreader mmreader
Summary of Multimedia Reader Object for 'traffic.avi'. Video Parameters: 15.00 frames per second, RGB24 160x120. 120 total video frames available.
273
17-12
17-12
imextendedmax 17-12 imextendedmax imextendedmax imopen 17-12 50
2 bwlabel regionprops
2
nframes = get(trafficObj, 'NumberOfFrames');% I = read(trafficObj, 1);% taggedCars = zeros([size(I,1) size(I,2) 3 nframes], class(I)); for k = 1 : nframes singleFrame = read(trafficObj, k);% I = rgb2gray(singleFrame);% noDarkCars = imextendedmax(I, darkCarValue);% noSmallStructures = imopen(noDarkCars, sedisk);%
lan 128 multibandread multibandread 17-14 4 3 2
paris
7
276
CIR Composite (Un-enhanced)
CIR Composite with Decorrelation Stretch
Image courtesy of Space Imaging, LLC
17-11
darkCarValue = 50;% darkCar = rgb2gray(read(trafficObj,71));% noDarkCar = imextendedmax(darkCar,darkCarValue);% figure; subplot(131) imshow(darkCar)% subplot(132); imshow(noDarkCar)% sedisk = strel('disk',2);% noSmallStructures = imopen(noDarkCar, sedisk);% subplot(133); imshow(noSmallStructures)%
17-13
17-13
17.4 在多分辨率图像中检测植被
275
例 17-5
decorrstretch NIR red
CIR = multibandread('paris.lan', [512, 512, 7], 'uint8=>uint8',... 128, 'bil', 'ieee-le',{'Band','Direct',[4 3 2]});% figure; subplot(121) imshow(CIR)% title('CIR Composite (Un-enhanced)') text(size(CIR,2), size(CIR,1) + 15,... 'Image courtesy of Space Imaging, LLC',... 'FontSize', 7, 'HorizontalAlignment', 'right') decorrCIR = decorrstretch(CIR, 'Tol', 0.01);% subplot(122) ; imshow(decorrCIR)% title('CIR Composite with Decorrelation Stretch')