clc
clear
close all
data=imread('2.jpg');
[mx,my,mz]= size(data);
data0=data;
figure
imshow(data)
a1 = reshape(data(:,:,1),mx,my);
a2 = reshape(data(:,:,2),mx,my);
a3 = reshape(data(:,:,3),mx,my);
n=1;
[x,y] = ginput(n);
x = round(x);
y = round(y);
cc=5;
tu = data(y-cc:y+cc,(x-cc:x+cc),:);
[mx,my,mz]=size(tu);
numu = [];
for ii = 1:mx
for jj = 1:my
numu = [numu;reshape(tu(ii,jj,:),1,3)];
end
end
zx = mean(numu);
pan =15;%黄色聚类参数
t=0;
[mx1,my1,mz1] = size(data);
for ii = 1:mx1
for jj = 1:my1
t = t+1;
if sqrt(sum((data(ii,jj,1)-zx(1,1)).^2+(data(ii,jj,2)-zx(1,2)).^2+(data(ii,jj,3)-zx(1,3)).^2))>pan
data(ii,jj,:) = [0 0 0];
end
end
end
I=data;
hsv = rgb2hsv( I );
g = rgb2gray( I );
% rgb转hsv
% 分别取出RGB的三个通道数据
R = I(:,:,1);
G = I(:,:,2);
B = I(:,:,3);
% 设置R、G、B三个通道的阈值
R_th = mean(mean(R(:,1:10)));
G_th = mean(mean(G(:,1:10)));
B_th = mean(mean(B(:,1:10)));
f = 1 * ones( size(g) );
II = double(I);
for ii = 1:size( g,1 )
for jj = 1:size(g,2)
% 结合灰度值、hsv颜色分布、rgb颜色分布,找到趋向白色区域
if sqrt(sum((II(ii,jj,1)-R_th).^2 + (II(ii,jj,2)-G_th).^2 + (II(ii,jj,3)-B_th).^2 ))>10
f( ii, jj ) = 0;
end
end
end
% 设置R、G、B三个通道的阈值
% f = ~round((f1+~f)/2);
% 显示
figure,
subplot(3,3,1), imshow( I ), title('原图');
subplot(3,3,2), imshow( f ), title('颜色分割');
% 取反
f = ~f;
subplot(3,3,3),imshow(f), title('颜色分割');
out=bwareaopen(f,5000);
subplot(3,3,5),imshow(out), title('去除小面积干扰区域');
out = ~out;
out=bwareaopen(out,5000);
out =~out;
% 设置滑动窗口大小
se = strel('disk',2);
% 膨胀计算
out = imdilate(out,se);
subplot(3,3,6),imshow(out), title('图像膨胀')
% 腐蚀计算
out = imerode(out,se);
subplot(3,3,4),imshow(out), title('图像腐蚀');
% 去img1除面积小于50个像素点的区域
;
% 填充孔洞
pic = imfill(out,'holes');
out = ~out;
out=bwareaopen(out,5000);
pic =~out;
subplot(3,3,7),imshow(pic), title('填充孔洞');
% 去除面积小于2000个像素点的区域
pic=bwareaopen(pic,2000);
subplot(3,3,8), imshow( pic ), title('去除小面积干扰区域');
% 图像联通区域标记
[ L, num ] = bwlabel( pic );
bw = pic;
res = [];
% figure,
for i = 1:num
[r,c] = find(L == i);
% 各个联通区域质心
coreX = mean( c );
coreY = mean( r );
% 各个联通区域坐标最大、最小值
x_min = min( c );
x_max = max( c );
y_min = min( r );
y_max = max( r );
% 联通区域中心位置
imgMiddleX = ( x_min + x_max )/2;
imgMiddleY = ( y_min + y_max )/2;
% 坐标的矩形面积
s = (y_max-y_min)*(x_max-x_min);
res = [ res; [ coreX coreY imgMiddleX imgMiddleY; length(r) s length(r)/s s-length(r) ] ];
if length(r)/s<0.5 %
for k = 1:length(r)
bw( r(k), c(k) ) = 0;
end
end
end
subplot(3,3,9), imshow( bw ), title('二值图');
figure,
subplot( 1,2,1 ), imshow( I ), title('原图');
% figure,imshow( cat(3, I(:,:,1) & bw,I(:,:,2) & bw,I(:,:,3) & bw) );
bw = double( bw );
I = double( I );
% data保存荷花区域图,其他区域为0
data = cat(3,I(:,:,1).*bw, I(:,:,2).*bw, I(:,:,3).*bw);
[mx,my,mz]= size(data);
for ii = 1:mx
for jj = 1:my
if bw(ii,jj)==1
data0(ii,jj,:) = [0 255 0]';
end
end
end
subplot( 1,2,2 ), imshow( uint8(data0) ), title('人像区域图');
data=imread('2.jpg');
[mx,my,mz]= size(data);
figure
imshow(data)
a1 = reshape(data(:,:,1),mx,my);
a2 = reshape(data(:,:,2),mx,my);
a3 = reshape(data(:,:,3),mx,my);
n=1;
[x,y] = ginput(n);
x = round(x);
y = round(y);
cc=5;
tu = data(y-cc:y+cc,(x-cc:x+cc),:);
[mx,my,mz]=size(tu);
numu = [];
for ii = 1:mx
for jj = 1:my
numu = [numu;reshape(tu(ii,jj,:),1,3)];
end
end
zx = mean(numu);
pan =10;%黄色聚类参数
t=0;
[mx1,my1,mz1] = size(data);
for ii = 1:mx1
for jj = 1:my1
t = t+1;
if sqrt(sum((data(ii,jj,1)-zx(1,1)).^2+(data(ii,jj,2)-zx(1,2)).^2+(data(ii,jj,3)-zx(1,3)).^2))>pan
data(ii,jj,:) = [0 0 0];
end
end
end
I=data;
hsv = rgb2hsv( I );
g = rgb2gray( I );
% rgb转hsv
% 分别取出RGB的三个通道数据
R = I(:,:,1);
G = I(:,:,2);
B = I(:,:,3);
% 设置R、G、B三个通道的阈值
R_th = mean(mean(R(:,1:10)));
G_th = mean(mean(G(:,1:10)));
B_th = mean(mean(B(:,1:10)));
f = 1 * ones( size(g) );
II = double(I);
for ii = 1:size( g,1 )
for jj = 1:size(g,2)
% 结合灰度值、hsv颜色分布、rgb颜色分布,找到趋向白色区域
if sqrt(sum((II(ii,jj,1)-R_th).^2 + (II(ii,jj,2)-G_th).^2 + (II(ii,jj,3)-B_th).^2 ))>10
f( ii, jj ) = 0;
end
end
end
% 设置R、G、B三个通道的阈值
% f = ~round((f1+~f)/2);
% 显示
figure,
subplot(3,3,1), imshow( I ), title('原图');
subplot(3,3,2), imshow( f ), title('颜色分割');
% 取反
f = ~f;
subplot(3,3,3),imshow(f), title('颜色分割');
out=bwareaopen(f,5000);
subplot(3,3,5),imshow(out), title('去除小面积干扰区域');
out = ~out;
out=bwareaopen(out,5000);
out =~out;
% 设置滑动窗口大小
se = strel('disk',3);
% 膨胀计算
out = imdilate(out,se);
subplot(3,3,6),imshow(out), title('图像膨胀')
% 腐蚀计算
se = strel('disk',2);
out = imerode(out,se);
subplot(3,3,4),imshow(out), title('图像腐蚀');
% 去img1除面积小于50个像素点的区域
;
% 填充孔洞
pic = imfill(out,'holes');
out = ~out;
out=bwareaopen(out,5000);
pic =~out;
subplot(3,3,7),imshow(pic), title('填充孔洞');
% 去除面积小于2000个像素点的区域
pic=bwareaopen(pic,2000);
subplot(3,3,8), imshow( pic ), title('去除小面积干扰区域');
% 图像联通区域标记
[ L, num ] = bwlabel( pic );
bw = pic;
% res = [];
% % figure,
% for i = 1:num
% [r,c] = find(L == i);
% % 各个联通区域质心
% coreX = mean( c );
% coreY = mean( r );
% % 各个联通区域坐标最大、最小值
% x_min = min( c );
% x_max = max( c );
% y_min = min( r );
% y_max = max( r );
% % 联通区域中心位置
% imgMiddleX = ( x_min + x_max )/2;
% imgMiddleY = ( y_min + y_max )/2;
%
% % 坐标的矩形面积
% s = (y_max-y_min)*(x_max-x_min);
%
%
% res = [ res; [ coreX coreY imgMiddleX imgMiddleY; length(r) s length(r)/s s-length(r) ] ];
%
%
% if length(r)/s<0.5 %
% for k = 1:length(r)
% bw( r(k), c(k) ) = 0;
% end
% end
%
% end
subplot(3,3,9), imshow( bw ), title('二值图');
figure,
subplot( 1,2,1 ), imshow( I ), title('原图');
% figure,imshow( cat(3, I(:,:,1) & bw,I(:,:,2) & bw,I(:,:,3) & bw) );
bw = double( bw );
I = double( I );
% data保存荷花区域图,其他区域为0
data = cat(3,I(:,:,1).*bw, I(:,:,2).*bw, I(:,:,3).*bw);
[mx,my,mz]= size(data);
for ii = 1:mx
for jj = 1:my
if bw(ii,jj)==1
data0(ii,jj,:) = [0 0 255 ]';
end
end
end
subplot( 1,2,2 ), imshow( uint8(data0) ), title('人像区域图');
data=imread('2.jpg');
[mx,my,mz]= size(data);
figure
imshow(data)
a1 = reshape(data(:,:,1),mx,my);
a2 = reshape(data(:,:,2),mx,my);
a3 = reshape(data(:,:,3),mx,my);
n=1;
[x,y] = ginput(n);
x = round(x);
y = round(y);
cc=5;
tu = data(y-cc:y+cc,(x-cc:x+cc),:);
[mx,my,mz]=size(tu);
numu = [];
for ii = 1:mx
for jj = 1:my
numu = [numu;reshape(tu(ii,jj,:),1,3)];
end
end
zx = mean(numu);
pan =15;%黄色聚类参数
t=0;
[mx1,my1,mz1] = size(data);
for ii = 1:mx1
for jj = 1:my1
t = t+1;
if sqrt(sum((data(ii,jj,1)-zx(1,1)).^2+(data(ii,jj,2)-zx(1,2)).^2+(data(ii,jj,3)-zx(1,3)).^2))>pan
data(ii,jj,:) = [0 0 0];
end
end
end
I=data;
hsv = rgb2hsv( I );
g = rgb2gray( I );
% rgb转hsv
% 分别取出RGB的三个通道数据
R = I(:,:,1);
G = I(:,:,2);
B = I(:,:,3);
% 设置R、G、B三个通道的阈值
R_
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
基于MATLAB编程,用基于支持向量机SVM的新鲜度等级预测,基于自适应粒子群优化长短期神经网络的新鲜度等级预测,代码完整,包含数据,有注释,方便扩展应用 1,如有疑问,不会运行,可以私信, 2,需要创新,或者修改可以扫描二维码联系博主, 3,本科及本科以上可以下载应用或者扩展, 4,内容不完全匹配要求或需求,可以联系博主扩展。
资源推荐
资源详情
资源评论
收起资源包目录
实验.rar (53个子文件)
mainsvm.m 2KB
MSE_RMSE_MBE_MAE.m 362B
2.jpg 32KB
calculate_roc.m 593B
example.sbn 123KB
example.cpg 5B
3.png 30KB
example.shx 99KB
example.dbf 1.39MB
example.shp 1.64MB
exampl.xls 1.49MB
example.shp.xml 787B
R_2.m 317B
main.m 510B
ispsolstm.m 7KB
1.png 15KB
example.sbx 8KB
confusion_matrix1.m 2KB
新建文件夹
mainsvm.m 3KB
Untitled4.m 3KB
MSE_RMSE_MBE_MAE.m 362B
2.jpg 32KB
calculate_roc.m 593B
example.sbn 123KB
example.cpg 5B
example.shx 99KB
example.dbf 1.39MB
example.shp 1.64MB
exampl.xls 1.49MB
example.shp.xml 787B
1.jpg 54KB
R_2.m 317B
main.m 589B
example.sbx 8KB
confusion_matrix1.m 2KB
maydata.mat 733KB
example.prj 441B
maysvm.mat 1.2MB
maintu.m 10KB
3.jpg 55KB
带坐标.xls 2.6MB
4.jpg 31KB
6.png 16KB
maincqi.m 1KB
maydata.mat 267KB
example.prj 441B
5.png 11KB
4.png 16KB
maysvm.mat 1.16MB
funcqi.m 377B
7.png 13KB
带坐标.xls 2.6MB
2.png 25KB
共 53 条
- 1
资源评论
神经网络机器学习智能算法画图绘图
- 粉丝: 2413
- 资源: 583
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功