根据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