Putting cropped images in seperate folder
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Abdussalam Elhanashi
el 3 de Mzo. de 2021
Respondida: Shivang Srivastava
el 24 de Mzo. de 2021
Hi,
I cropped images with size 200 x 200 into 4 tiles with 50 x 50 for each tile and i want to make these generated tiles into seperated folder
Herein the code
close all;
clc;
%% Initalize the data
dataDir= fullfile('Data/');
exts = {'.jpg','.png','.tif','BMP'};
imds = imageDatastore(fullfile(dataDir),...
'IncludeSubfolders',true,'FileExtensions','.jpg','LabelSource','foldernames');
countEachLabel(imds);
[TrainData, TestData] = splitEachLabel(imds,0.5);
size(TrainData);
countEachLabel(TrainData);
numImages = numel(TrainData.Files);
dx = 50;
dy = 50;
w = dx - 1;
h = dy - 1;
for i = 1:numImages
img = readimage(TrainData, i);
img=rgb2gray(img);
img3= im2double(img);
scale = 0.5;
img8 = imresize(img3,scale);
for x = 0:2
for y = 0:2
ofs_x = 1 + x * dx;
ofs_y = 1 + y * dy;
img_crop = imcrop(img8,[ofs_x ofs_y w h]);
%img4 = imshow(img_crop, 'InitialMagnification',800);
%drawnow;
idx = (i-1)*4 + y*2 + x + 1;
% 1 2 4 5
% 6 7 8 9
% 10 11 12 13
% 14 15 16 17
Train{idx} = (img_crop); %#ok<SAGROW>
end
end
end
The code Train{idx} is the for generated tiles 50 x 50
Looking for your support
0 comentarios
Respuestas (1)
Shivang Srivastava
el 24 de Mzo. de 2021
Hi Abdussalam,
As per my understanding you need to put the cropped tiles in Train variable into another folder. I am assuming that you are trying to do that as an .jpg file. The below code would help you to the same.
mkdir croppedImages
for i = [1:size(Train,2)]
K = mat2gray(Train{i});
imwrite(K,"croppedImages/"+string(i)+".jpg",'jpg');
end
0 comentarios
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!