✅作者简介:热爱科研的Matlab仿真开发者,修心和技术同步精进,matlab项目合作可私信。
🍎个人主页:Matlab科研工作室
🍊个人信条:格物致知。
更多Matlab仿真内容点击👇
⛄ 内容介绍
苹果梗蒂和缺陷的识别是苹果自动检测中的难点,两者的误分类会造成苹果质量等级的误判.介绍了一个基于机器视觉的苹果质量自动评价系统.通过梗蒂识别,缺陷分割,确定缺陷区域并移除梗蒂区域,形成新的兴趣区域;提取统计,纹理和几何特征,采用Pearson特征相关性分析和SFFS特征选择,删除冗余特征;采用模糊KNN分类器在富士苹果进行试验,得到的平均识别正确率为83%.这项技术可以用于苹果包装流水线作业,也可用于类似的农产品外观质量检测.
⛄ 部分代码
%XYZ = rgb2xyz(RGB)
%
%Output parameter: RGB must be an image having 3 channels, i.e. a 3D array.
% Each channel of RGB should be in the range 0..255.
%Input parameter: XYZ would be an image of the same dimension.
%
%Example: To convert an image in RGB format to L*a*b* format, one can
%combine the calling to the rgb2xyz and xyz2lab functions:
% rgbim = imread('yourImage.png'); % image in RGB format
% labim = xyz2lab(rgb2xyz(rgbim));
%The output labim has the following ranges of values:
% - first channel L* 0..100
% - the second channel a* -128..127
% - the third channel b -128..127
%
%Other software packages, e.g. OpenCV, often applies a normalisation
%process so that images in the L*a*b* format can be stored as 3-channel
%greyscale images. The normalisation adopted by OpenCV is:
% - the first channel L* is rescaled to the range 0..255. This can be done
% easily by multiplying by 255 and dividing by 100.
% - the second channel a* and third channel b* are added by 128 to bring
% the range from -128..127 to 0..255.
%
%When comparing the pixel values of an L*a*b* image produced by the Matlab
%function here and those from OpenCV, ensure that the above normalisation
%procedure is taken into account.
%
%Also noted that images that are read from disk into OpenCV have their
%channels specified in reverse order in the data structure. So, to compare
%the Matlab function here with those in OpenCV, use the following OpenCV
%functions:
% source_rgb_image = cvLoadImage('yourImage.png', 1);
% // make sure that the 3rd parameter is CV_BGR2Lab and not CV_RGB2Lab
% cvCvtColor(source_rgb_image, destination_lab_image, CV_BGR2Lab);
% // the resultant L*a*b* image is created within the program (i.e. not
% // read from disk), so the channels are in the right order:
% cvCvtPixToPlane(destination_lab_image, l_channel, a_channel, b_channel,
% 0);
%
%References:
%* http://www.easyrgb.com/index.php?X=MATH
%* http://en.wikipedia.org/wiki/SRGB_color_space
%
%SEE ALSO
% xyz2rgb, xyz2lab, lab2xyz
%
%Feb 2010
%
%Copyright Du Huynh
%School of Computer Science and Software Engineering
%The University of Western Australia
RGB = RGB/255;
index1 = find(RGB > 0.04045);
index2 = find(RGB <= 0.04045);
RGB(index1) = ((RGB(index1) + 0.055) / 1.055).^2.4;
RGB(index2) = RGB(index2) / 12.92;
%Observer. = 2°, Illuminant = D65
XYZ = zeros(size(RGB));
M = [
0.4124 0.3576 0.1805;
0.2126 0.7152 0.0722;
0.0193 0.1192 0.9505
];
for i=1:3
XYZ(:,:,i) = RGB(:,:,1)*M(i,1) + RGB(:,:,2)*M(i,2) + RGB(:,:,3)*M(i,3);
end
XYZ = XYZ*100;
end
⛄ 运行结果
⛄ 参考文献
[1]蒋益女, 徐从富. 基于机器视觉的苹果质量等级识别方法的研究[J]. 计算机应用与软件, 2010, 27(11):3.
[2]童旭. 基于机器视觉水果表面等级分类识别的研究[D]. 重庆交通大学, 2018.