% Subtract the Background Image from the Original Image I2 = imsubtract(I,background); figure, imshow(I2) % Adjust the Image Contrast I3 = imadjust(I2, stretchlim(I2), [0 1]); figure, imshow(I3);
% Apply Thresholding to the Image level = graythresh(I3); bw = im2bw(I3,level); figure, imshow(bw)
% Determine the Number of Objects in the Image
[labeled,numObjects] = bwlabel(bw,4); % Label components. numObjects
% Examine the Label Matrix
RGB_label = label2rgb(labeled, @spring, 'c', 'shuffle'); figure, imshow(RGB_label);
% Measure Object Properties in the Image graindata = regionprops(labeled,'basic') allgrains = [graindata.Area];
% Compute Statistical Properties of Objects in the Image max(allgrains);
biggrain = find(allgrains==695) mean(allgrains); figure, hist(allgrains,20);
(详见MATLAB IPT的 帮助文档demo中的Correcting Nonuniform Illumination)
(二)查看MATLAB IPT 帮助文档,研究其它应用演示
三、实验设备
1.PIII以上微机; 2.MATLAB6.5;
四、预习与思考
1.预习实验内容,阅读教材熟悉实验原理; 2.查阅资料,熟悉实验中涉及的有关函数。
3.利用课余时间,采用MATLAB函数编程实现实验内容(二)。
29
五、实验报告要求
1.简述试验的目的和试验原理;
2.叙述各段程序功能,改变有关函数的参数,分析比较实验结果; 3.打印出所编写的实验程序。 4.写出本实验的心得体会及意见。
30