Extract Imges
% Demo
clc
clearvars
close all
name = '061.png';
img = imread(['Input/',name]);
Path = '/Users/thaweesaktrongtirakul/Desktop/';
Size = [100 100]; %[Width Height]
Initial_Position = [80 80]; %[Col Row]
pos = cat(2,Initial_Position,Size);
weight = 2;
Extract_Image(img, pos, weight, Path,'01 - IMG');
function [mark,corp] = Extract_Image(img,pos,weight,Path,Name)
mark = insertShape(img,"rectangle",pos,Color="red",LineWidth=weight);
for i = 1:size(img,3)
corp(:,:,i) = img(pos(2):pos(2)+pos(4),pos(1):pos(1)+pos(3),i);
end
imwrite(mark, [Path,Name,'_mark.png'],'png');
imwrite(corp, [Path,Name,'_corp.png'],'png');
end