I = imread(‘rice.png‘);
subplot(1,3,1); imshow(I);
BG = imopen(I, strel(‘disk‘, 15));
subplot(1,3,2); imshow(BG);
I2 = imsubtract(I, BG);
subplot(1,3,3); imshow(I2);
I2 = imsubtract(I, BG); level=graythresh(I2);
bw2 = im2bw(I2, level);
graythresh()
使用最大类间方差法找到图片的一个合适的阈值(threshold)。m2bw()
使用阈值(threshold)变换法把灰度图像(grayscale image)转换成二值图像。bwlable
计算连通区域,该函数使用了连通区域标记算法,将每个连通区域内的像素点赋值为同一个值.I=imread(‘rice.png‘);
BG=imopen(I, strel(‘disk‘, 15));
I2=imsubtract(I, BG); level=graythresh(I2);
BW=im2bw(I2, level);
[labeled, numObjects]=bwlabel(BW, 8);
lable2rgb()
I=imread(‘rice.png‘);
BG=imopen(I, strel(‘disk‘, 15));
I2=imsubtract(I, BG); level=graythresh(I2);
BW=im2bw(I2, level);
[labeled, numObjects]=bwlabel(BW, 8);
RGB_label=label2rgb(labeled); imshow(RGB_label);
regionprops()
:可以将检测结果封装成结构体数组.I=imread(‘rice.png‘);
BG=imopen(I, strel(‘disk‘, 15));
I2=imsubtract(I, BG); level=graythresh(I2);
BW=im2bw(I2, level);
[labeled, numObjects]=bwlabel(BW, 8);
graindata = regionprops(labeled, ‘basic‘);
graindata(51)
Area: 155
Centroid: [112.4258 245.8645]
BoundingBox: [108.5000 234.5000 8 22]
bwselect()
:鼠标选择连通区域.I=imread(‘rice.png‘); level=graythresh(I);
BG=imopen(I, strel(‘disk‘, 15));
I2=imsubtract(I, BG); BW=im2bw(I2, graythresh(I2));
ObjI = bwselect(BW); imshow(ObjI);
原文:https://www.cnblogs.com/thrseven/p/15259632.html