⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cut_to_piece.m

📁 将某个文件夹下的所有图片分块保存到目的文件夹下
💻 M
字号:
function [piece] = cut_to_piece(o_path, s_path, widthsize, heightsize)

%% 将某个文件夹下的所有图片分块保存到目的文件夹下
%  author     :(whu/spl&xy)/YaAnn 2008.11 
%  o_path     :源文件夹路径
%  s_path     :目的文件夹路径
%  widthsize  :分块宽
%  heightsize :分块高
%  piece      : 分块总数 
%  example    : 128 * 128 cut
%              openpath = fullfile('F:\database\airplane','/*.jpg');
%              savepath = fullfile('F:\database\airplane_cut','/');
%              cutsize  = 128;
%              piece    = cut_to_piece(openpath,savepath,cutsize);

%%
if nargin < 4
    heightsize = widthsize;    %均匀分块
end

cate_list = dir(o_path);
   n_cate = size(cate_list,1);
  o_path0 = o_path(1:end-5);
        p = 0;
        
for k = 1:n_cate
    groundtruce_file_name = strcat(o_path0,cate_list(k).name);
    imdata = imread(groundtruce_file_name);
    if isrgb(imdata)
        imdata = rgb2gray(imdata);
    end
    [height, width] = size(imdata);
    num_i = floor(height/heightsize);
    num_j = floor(width/widthsize);
    for i = 1:num_i
        for j = 1:num_j
            p = p + 1;
            tmpstr = num2str(p);
            tmpstr = [s_path, tmpstr, '.jpg'];
            imwrite(imdata(((i-1)*heightsize+1):(i*heightsize), ((j-1)*widthsize+1):(j*widthsize)),tmpstr, 'jpg');
         end
     end
end
piece = p;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -