matlab取图像的四个角和中间的方块


% Augment a image into 5 througn choosing 5 regions of the image which are top left corner, top right
% corner, lower left quarter, lower right quarter and middle.

clc;
clear all;

originPath_test = 'D:\CaffeInfo\B_DataCreate\test_image\';
aimPath_test  = 'D:\CaffeInfo\B_DataCreate\crop_picture_test\';

files = dir([originPath_test, '*.tif'])
num = length(files)


for i = 1 : num
    filename0 = files(i).name
    filename0 = filename0(1:end-4) % the first part of the new name 
    filename1 = files(i).name;
    path_name = [originPath_test, filename1] 
    ImageData = imread(path_name); % read the original image
    
    picture1 = ImageData(1:224,1:224,:); % top left corner
    imwrite(picture1, [aimPath_test , filename0, '_1.tif'],'tif');
    picture2 = ImageData(32:256,1:224,:); % top right corner
    imwrite(picture2, [aimPath_test , filename0, '_2.tif'],'tif');
    picture3 = ImageData(1:224,32:256,:); % bottom left corner
    imwrite(picture3, [aimPath_test , filename0, '_3.tif'],'tif');
    picture4 = ImageData(32:256,32:256,:); % bottom right corner
    imwrite(picture4, [aimPath_test , filename0, '_4.tif'],'tif');
    picture5 = ImageData(16:240,16:240,:); % center
    imwrite(picture5, [aimPath_test , filename0, '_5.tif'],'tif');
    
end




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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值