没有合适的资源?快使用搜索试试~ 我知道了~
基于libsvm的图像分割代码
需积分: 50 24 下载量 58 浏览量
2019-03-22
11:15:19
上传
评论 2
收藏 4KB TXT 举报
温馨提示
试读
6页
基于libsvm的图像分割代码,亲测有效,可以自行训练若干样本,libsvm工具箱下载请参考台湾大学林智任。
资源推荐
资源详情
资源评论
我们建议初学者先尝试以下处理流程:
1.将数据转换成SVM包指定的格式
2.对数据进行简单缩放处理
3.考虑使用RBF核
4.使用交叉验证找到最佳的参数来训练整个数据集
5.使用最佳参数 和 来训练整个数据集(最佳参数可能会受数据集大小的的影响,但是在实践中发现在交叉验证中获得的参数已经可以很好地拟合整个训练集)
6.测试
make
pic_initial=imread('little duck.png');
%读入图片
pic=im2double(pic_initial);
%简单缩放处理
scrsz=get(0,'ScreenSize');
%电脑的分辨率是1440*960
figure('Position',[scrsz(3)*1/4 scrsz(4)*1/6 scrsz(3)*4/5 scrsz(4)]*3/4);
%To create a figure window that is one quarter the size of your screen;[left bottom width height].
%imshow(pic);
TrainData_background=zeros(20,3,'double');
%创建20*3的零阵
TrainData_foreground=zeros(20,3,'double');
%创建20*3的零阵
1.将数据转换成SVM包指定的格式
2.对数据进行简单缩放处理
3.考虑使用RBF核
4.使用交叉验证找到最佳的参数来训练整个数据集
5.使用最佳参数 和 来训练整个数据集(最佳参数可能会受数据集大小的的影响,但是在实践中发现在交叉验证中获得的参数已经可以很好地拟合整个训练集)
6.测试
make
pic_initial=imread('little duck.png');
%读入图片
pic=im2double(pic_initial);
%简单缩放处理
scrsz=get(0,'ScreenSize');
%电脑的分辨率是1440*960
figure('Position',[scrsz(3)*1/4 scrsz(4)*1/6 scrsz(3)*4/5 scrsz(4)]*3/4);
%To create a figure window that is one quarter the size of your screen;[left bottom width height].
%imshow(pic);
TrainData_background=zeros(20,3,'double');
%创建20*3的零阵
TrainData_foreground=zeros(20,3,'double');
%创建20*3的零阵
msgbox('Please get 20 background samples(单击OK后再按任意键继续)','Background Samples','help');
%{
Create message dialog box
对话框显示Please get 20 background samples(单击OK后再按任意键继续)的消息
名称为Background Samples,图标为help
%}
pause;
%pause temporarily stops MATLAB execution and waits for the user to press any key
imshow(pic);
for run =1:16
[x,y]=ginput(1); %Pick two-dimensional points from the figure window
axis on
hold on;
plot(x,y,'r*');
x=uint8(x); %Convert to 8-bit unsigned integer(无符号整数)
y=uint8(y);
TrainData_background(run,1)=pic(x,y,1);
TrainData_background(run,2)=pic(x,y,2);
TrainData_background(run,3)=pic(x,y,3); %选取20个背景点将数据输入到TrainData_background(20*3)里
end
axis off
msgbox('Please get 20 foreground samples which is the part to be segmented(单击OK后再按任意键继续)','Foreground Samples','help');
pause;
imshow(pic);
for run =1:16
[x,y]=ginput(1);
hold on;
plot(x,y,'bo');
x=uint8(x);
%{
Create message dialog box
对话框显示Please get 20 background samples(单击OK后再按任意键继续)的消息
名称为Background Samples,图标为help
%}
pause;
%pause temporarily stops MATLAB execution and waits for the user to press any key
imshow(pic);
for run =1:16
[x,y]=ginput(1); %Pick two-dimensional points from the figure window
axis on
hold on;
plot(x,y,'r*');
x=uint8(x); %Convert to 8-bit unsigned integer(无符号整数)
y=uint8(y);
TrainData_background(run,1)=pic(x,y,1);
TrainData_background(run,2)=pic(x,y,2);
TrainData_background(run,3)=pic(x,y,3); %选取20个背景点将数据输入到TrainData_background(20*3)里
end
axis off
msgbox('Please get 20 foreground samples which is the part to be segmented(单击OK后再按任意键继续)','Foreground Samples','help');
pause;
imshow(pic);
for run =1:16
[x,y]=ginput(1);
hold on;
plot(x,y,'bo');
x=uint8(x);
剩余5页未读,继续阅读
资源评论
@Cocoder
- 粉丝: 0
- 资源: 4
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功