MATLAB【四】 ————批量适配图片信息与excel/txt等文档信息,批量移动拷贝图片,批量存图片中点和方框

1、批量读取图片,批量读取文件

2、适配文件与excel、txt等文档信息

3、获取显示图片ROI、Point、rect、更改像素值

4、批量移动拷贝图片,批量显示

5、保存显示图片或者图片中的点和方框。

clear;
clc;
close all;

%% crop the im into 256*256
num = 0;    %% num=1 内缩3个像素  num =2  内缩6个像素  

load('qualitydata1.mat')
load('qualitydata2.mat')
 
[data1_m,data1_n] = size(qualitydata1);
[data2_m,data2_n] = size(qualitydata2);

%% read image_name in filepath

% file_path =  'D:\matlab\motive_vs_exe\data\cg\30\15\';% 图像文件夹路径  
% img_path_list_bmp = dir(strcat(file_path,'*.png'));%获取该文件夹中所有bmp格式的图像  
% img_num = length(img_path_list_bmp);%获取图像总数量 
% I=cell(1,img_num);
% if img_num > 0 %有满足条件的图像  
%         for j = 1:img_num %逐一读取图像  
%             image_name = img_path_list_bmp(j).name;% 图像名  
%             image =  imread(strcat(file_path,image_name));  
%             I{j}=image;
%            fprintf('%d %d %s\n',i,j,strcat(file_path,image_name));% 显示正在处理的图像名  
%             %图像处理过程 省略  
%             %这里直接可以访问细胞元数据的方式访问数据
%         end  
% end  
%% readme  suitable for three layers of the file like  cg/30/1  cg/30/2 ... cg/30/10   .....cg/100/1 ...cg/100/10
%% 
oriDataPath = 'D:\matlab\motive_vs_exe\data\';  
saveDirPath = 'D:\matlab\motive_vs_exe\we_chat_data\';

imgDataDirList  = dir(oriDataPath);             % 遍历所有文件
layer_1_list = imgDataDirList(3:end);
% 
for i = 1:length(layer_1_list)
    layer_1_list_folder =layer_1_list(i,:).folder; 
    layer_1_list_name =layer_1_list(i,:).name; 
    layer_2_list = dir( fullfile(layer_1_list_folder,layer_1_list_name));
    layer_2_list = layer_2_list(3:end); 
    
    for i2 = 1:length(layer_2_list)
        layer_2_list_folder=layer_2_list(i2,:).folder; 
        layer_2_list_name =layer_2_list(i2,:).name; 
        layer_3_list = dir( fullfile(layer_2_list_folder,layer_2_list_name));
        layer_3_list = layer_3_list(3:end); 
        
         for i3 = 1:length(layer_3_list)
             layer_3_list_folder=layer_3_list(i3,:).folder; 
             layer_3_list_name =layer_3_list(i3,:).name; 
             layer_4_list = dir( fullfile(layer_3_list_folder,layer_3_list_name));
             layer_4_list = layer_4_list(3:end); 
             
%              for i4 = 1:1
%                      layer_4_list_folder=layer_4_list(i4,:).folder; 
                     layer_4_list_folder=layer_4_list.folder;
                     layer_4_list_name =layer_4_list(2,:).name; 
%                      layer_5_list =  fullfile(layer_3_list_folder,layer_3_list_name);

                     for j = 1:data1_m
                                     key = qualitydata1(j,:).key;
                                     key_fore = split(key,'.');
                                     str_key = key_fore(1);   %%%% get excel str
                                     str_key = replace(str_key,'/','\');
                                     %%%%%%%%%%%%%%%%%judge whether the
                                     %%%%%%%%%%%%%%%%%same depth and then deal with it  
                                     str_aim = replace(layer_4_list_folder,oriDataPath,'');                                     
                                     if(isequal(str_aim,str_key))
                                             rect_x = qualitydata1(j,:).rect_x;
                                             rect_y = qualitydata1(j,:).rect_y;
                                             rect_width = qualitydata1(j,:).rect_width;
                                             rect_height = qualitydata1(j,:).rect_height;
                                             
                                             point_0_x = qualitydata1(j,:).point_0_x;
                                             point_0_y = qualitydata1(j,:).point_0_y;
                                             point_1_x = qualitydata1(j,:).point_1_x;
                                             point_1_y = qualitydata1(j,:).point_1_y;
                                             point_2_x = qualitydata1(j,:).point_2_x;
                                             point_2_y = qualitydata1(j,:).point_2_y;
                                             point_3_x = qualitydata1(j,:).point_3_x;
                                             point_3_y = qualitydata1(j,:).point_3_y;
                                             point_4_x = qualitydata1(j,:).point_4_x;
                                             point_4_y = qualitydata1(j,:).point_4_y;

                                             %% change roi 

                                             rect_x = rect_x + 3*num ;
                                             rect_y = rect_y + 3*num ;
                                             rect_width = rect_width -  2*3*num;
                                             rect_height = rect_height - 2*3*num;
                                             %% 

                                             roi = [rect_x,rect_y,rect_width,rect_height];

                                             path_depth = fullfile(layer_4_list_folder,'depth.png');
                                             depth_image = imread(path_depth);

                                             path_ir = fullfile(layer_4_list_folder,'auto_rectified_ir.png');
                                             ir_image = imread(path_ir);

                                             path_rgb = fullfile(layer_4_list_folder,'rgb.jpg');
                                             rgb_image = imread(path_rgb);

    %                                          figure, imshow(depth_image*255, 'border', 'tight')                                            
    %                                          Point  = roi;
    %                                          hold on;
    %                                          rectangle('Position', roi, 'LineWidth', 2, 'EdgeColor', 'r')  %%
    %                                          rectangle('Position', Point, 'LineWidth', 2, 'EdgeColor', 'r')

                                            [image_h,image_w] = size(depth_image); 
                                             for jj = 1:1:image_h
                                                for ii = 1:1:image_w
                                                        if ((jj>rect_y)&&(jj<rect_y + rect_height))
                                                                if ((ii>rect_x)&&(ii<rect_x + rect_width))
                                                                        continue;
                                                                else
                                                                     depth_image(jj,ii) = 0;
                                                                end
                                                        else
                                                            depth_image(jj,ii) = 0;
                                                        end   
                                                end
                                             end
                                             %%    imwshow(roi_depth,)
%                                              figure, imshow(depth_image*255, 'border', 'tight')          %%depth  show    
                                              figure, imshow(rgb_image, 'border', 'tight')                  %%rgb show    
                                              Point  = roi;
                                              hold on;
                                              rectangle('Position', roi, 'LineWidth', 2, 'EdgeColor', 'r')  %%
                                              rectangle('Position', Point, 'LineWidth', 2, 'EdgeColor', 'r')
                                              
                                              text(point_0_x,point_0_y,'o','color','g');                  %%key point show on rgb
                                              text(point_1_x,point_1_y,'o','color','g');
                                              text(point_2_x,point_2_y,'o','color','g');
                                              text(point_3_x,point_3_y,'o','color','g');
                                              text(point_4_x,point_4_y,'o','color','g');
                                          %%   save depth roi
                                             new_str_aim = split(str_aim,'\');
                                             savePathDepth = fullfile(saveDirPath,char(new_str_aim(1)),char(new_str_aim(2)),'depth\');
                                             mkdirDepthDir = mkdir(savePathDepth); 
                                             imwrite(depth_image,[savePathDepth,char(new_str_aim(3)),'.png']);
                                             %%%remove rgb and ir pic and change its name
                                         %% saveas(figure(num2str((char(new_str_aim(3))))), [savePathDepth,char(new_str_aim(3)),'.png'])
                                             savePathIr = fullfile(saveDirPath,char(new_str_aim(1)),char(new_str_aim(2)),'ir\');
                                             mkdirIrDir = mkdir(savePathIr); 
                                             imwrite(ir_image,[savePathIr,char(new_str_aim(3)),'.png']);

                                             savePathRgb = fullfile(saveDirPath,char(new_str_aim(1)),char(new_str_aim(2)),'rgb\');
                                             mkdirRgbDir = mkdir(savePathRgb);
                                             imwrite(rgb_image,[savePathRgb,char(new_str_aim(3)),'.jpg']);
                                             
                                         %% saveas(figure(), [savePathRgbKeyPoint,char(new_str_aim(3)),'.jpg']);
                                             savePathRgbKeyPoint = fullfile(saveDirPath,'rgbKeyPointDir',char(new_str_aim(2)));
                                             mkdirRgbKeyPointDir = mkdir(savePathRgbKeyPoint);
                                             frame = getframe(gcf);
                                             result = frame2im(frame);
                                             imwrite(result,[savePathRgbKeyPoint,char(new_str_aim(3)),'.jpg']);
                                                                                                                                    
                                     end
                                     
                     end
                    
                                 
%              end              
         end
    end
end   
 
1

getframe

捕获坐标区或图窗作为影片帧

frame2im

返回与影片帧关联的图像数据

 

F = getframe 捕获显示在屏幕上的当前坐标区作为影片帧。F 是一个包含图像数据的结构体。getframe 按照屏幕上显示的大小捕获这些坐标区。它并不捕获坐标区轮廓外部的刻度标签或其他内容

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

大江东去浪淘尽千古风流人物

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值