www.gusucode.com > 颗粒提取源码程序 > 颗粒提取源码程序/ex1.m

    clc;
clear;
close all;

I = imread('chrimage.bmp');
figure,imshow(I);
I2 = rgb2gray(I);
s = size(I2);
I4 = 255*ones(s(1), s(2), 'uint8');
I5 = imsubtract(I4,I2);
I3 = medfilt2(I5,[5 5]);
I3 = imadjust(I3);
bw = im2bw(I3, 0.3);
bw = bwareaopen(bw, 10);
figure,imshow(bw);
[labeled,numObjects] = bwlabel(bw,4);
RGB_label=label2rgb(labeled,@spring,'c','shuffle');
figure,imshow(RGB_label);
chrdata = regionprops(labeled,'basic')
allchrs = [chrdata.Area];
num = size(allchrs)
nbins = 20;
figure,hist(allchrs,nbins);
title(num(2))