Matlab批量二值化图片保存及基本操作

1.批量二值化及保存


clc;
clear;
file_path =  'E:\spyder\spineunet-1\data\train\image\';% 图像文件夹路径
img_path_list = dir(strcat(file_path,'*.jpg'));%获取该文件夹中所有jpg格式的图像
img_num = length(img_path_list);%获取图像总数量
if img_num > 0 %有满足条件的图像
        for j = 1:img_num %逐一读取图像
            image_name = img_path_list(j).name;% 图像名
            IM =  imread(strcat(file_path,image_name));
            %fprintf('%d %d %s',i,j,strcat(file_path,image_name));% 显示正在处理的图像名
            
            %自适应滤波
            im=wiener2(IM,[3,3]);
            
            %二值化
            thresh=graythresh(im);
            im=im2bw(im,thresh);
             
%            %****平滑滤波****
%            h=ones(3,3)/5;
%            h(1,1)=0;h(1,3)=0;h(3,1)=0;h(1,3)=0;
%            im=imfilter(IM,h);

%            %****中值滤波****
%            im=medfilt2(IM,[3,3]);

%              %****均值滤波****
%              fsp=fspecial('average',3);
%              im=imfilter(IM,fsp);
            %figure;
            %imshow(im);
            saveddir='E:\matlab\gxy\';
            savedname=fullfile(saveddir,image_name);
            imwrite(im,savedname);
           
        end
end
               

`2.滤波、开闭运算

I=imread('test16.bmp');
thresh=graythresh(I);
bw=im2bw(I,thresh);

%****平滑滤波****
h=ones(3,3)/5;
h(1,1)=0;h(1,3)=0;h(3,1)=0;h(1,3)=0;
I1=imfilter(I,h);
thresh1=graythresh(I1);
bw1=im2bw(I1,thresh1);
se1=strel('line',5,200);%直线长度7,角度85
img1=imopen(bw1,se1);%开运算
img2=imclose(bw1,se1);%闭运算
img3=imclose(img1,se1);%先开后闭运算
img4=imopen(img2,se1);%先闭后开运算
img5=imdilate(bw1,se1);%膨胀操作
img6=imerode(bw1,se1);%腐蚀
figure(1);
subplot(331)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值