根据mat几列数据,选图、做txt

根据mat几列数据,选图、做txt

clc;

A = load('H:\余高-熔深\2019-09-26余高与序号-23道\10-16.mat');
fpath1 = 'M:\熔深数据\熔深源数据\增材40\00022\0009\txt\';
fpath = 'H:\余高-熔深\新余高\20190627-num\第二道\09\image\';
name = dir(fpath);
 
fpath1_img = 'M:\熔深数据\熔深源数据\增材40\00022\0009\img\';
A_struct = struct2cell(A);
A_num = A_struct{1,1}(:,1);
A_len = A_struct{1,1}(:,2);
%depth = A_struct{1,1}(:,3);
height = A_struct{1,1}(:,3);
% figure(2);
%plot(depth);hold on;
plot(height); hold on ;
% plot(A_len); hold on ;
%20-38

% for i = 515:708
%     height(i,:) = height(i,:)+0.2105;
% end
% 
% plot(height);
% for i = 331:1026
%     height(i,:) = height(i,:)+0.3980;
% end
% height(331,:) = 2.6140;
% for i = 149:1026
%     height(i,:) = height(i,:)+0.175;
% end
% plot(height);

% %20-32
% for i = 500:653
%     height(i,:) = height(i,:)+0.2055;
% end
% plot(height);
% height(654,:) = 2.6040;
% plot(height);
% for i = 655:1023
%     height(i,:) = height(i,:)+0.0340;
% end
% plot(height);
% for i = 129:1023
%     height(i,:) = height(i,:)+0.2;
% end
% height(127,:) = 2.575;
% height(128,:) = 2.575;
% plot(height);

[a,b] = size(height);

cc = 1;
for id = 3:length(name)
    wholename=strcat(fpath,name(id).name);
    
    img_name = name(id).name;
    img_len = length(img_name);
    img_num = str2double(img_name(1:img_len-4));
%     if(img_len==64)
%         img_num = str2double(img_name(img_len-13:img_len-9));
%     else
%         img_num = str2double(img_name(img_len-14:img_len-9));
%     end
    
    for i = 1:a
        height_int = height(i,:);
        A_lengthh = A_len(i,:);
        if(A_lengthh>0.0 && A_lengthh < 70.0)
            height_num = A_num(i,:);
            if(img_num==(height_num))
                img = imread(wholename);
                img = demosaic(img,'bggr');
%                 figure(1);imshow(img);
                %roi = imcrop(img,[0,5,200,100]);%用roi选取感兴趣区域
                %figure();imshow(roi);
                %depth_int = depth(i,:);
                if( height_num>99&&height_num<1000)
                    filePath = strcat(fpath1,'00', num2str(height_num),'.txt');
                    filePath1 = strcat(fpath1_img,'00', num2str(height_num),'.tiff');
                elseif(height_num < 100 && height_num>9)
                    filePath = strcat(fpath1,'000', num2str(height_num),'.txt');
                    filePath1 = strcat(fpath1_img,'000', num2str(height_num),'.tiff');
                elseif(height_num < 10)
                    filePath = strcat(fpath1,'0000', num2str(height_num),'.txt');
                    filePath1 = strcat(fpath1_img,'0000', num2str(height_num),'.tiff');
                elseif(height_num > 999 && height_num<10000)
                    filePath = strcat(fpath1,'0', num2str( height_num),'.txt');
                    filePath1 = strcat(fpath1_img,'0', num2str(height_num),'.tiff');
                else
                    filePath = strcat(fpath1, num2str( height_num),'.txt');
                    filePath1 = strcat(fpath1_img, num2str(height_num),'.tiff');
                end
                
                fid=fopen(filePath,'wt');
                fprintf(fid,'%.4f',height_int);
                %
                fclose(fid);%关闭文件。
                
                wholename_test=sprintf('%s',filePath1);
                imwrite(img,wholename_test);
            end
        end
    end
end



















  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值