MATLAB【四】 ————批量适配图片信息与excel/txt等文档信息,批量移动拷贝图片,批量存图片中点和方框
生活随笔
收集整理的這篇文章主要介紹了
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_mkey = qualitydata1(j,:).key;key_fore = split(key,'.');str_key = key_fore(1); %%%% get excel strstr_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_hfor ii = 1:1:image_wif ((jj>rect_y)&&(jj<rect_y + rect_height))if ((ii>rect_x)&&(ii<rect_x + rect_width))continue;elsedepth_image(jj,ii) = 0;endelsedepth_image(jj,ii) = 0;end endend%% 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 rgbtext(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 roinew_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']);endend% end endend
end 1
getframe
捕獲坐標區或圖窗作為影片幀
frame2im
返回與影片幀關聯的圖像數據
?
?捕獲顯示在屏幕上的當前坐標區作為影片幀。F?= getframeF?是一個包含圖像數據的結構體。getframe?按照屏幕上顯示的大小捕獲這些坐標區。它并不捕獲坐標區輪廓外部的刻度標簽或其他內容
?
?
總結
以上是生活随笔為你收集整理的MATLAB【四】 ————批量适配图片信息与excel/txt等文档信息,批量移动拷贝图片,批量存图片中点和方框的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: OpenCV 【十】——Gamma校正
- 下一篇: 公务员一个月多少钱啊?