Alter and store images back into an excisting imagedatastore
Mostra commenti meno recenti
Hi All,
I'm new to Matlab and need some help on how to alter and store images back into an (excisting) imagedatastore.
I already figured out how to read a bunch of images (which are labeled) and then, based on the largest object in the image, calculate and crop/resize the image for further processing.
I now need to update the original image in the imagedatastore with the new crop/resized image. Is this possible and how.
Kind regards
Bert
Code :
ORIGINAL = imageDatastore(digitDatasetPath,...
'IncludeSubfolders',true,'LabelSource','foldernames');
while hasdata(ORIGINAL)
% Clean up image
B = read(ORIGINAL);
BW = rgb2gray(B);
BW2 = imbinarize(BW);
% Label the image
labeledImage = bwlabel(BW2);
measurements = regionprops(BW2, 'BoundingBox', 'Area');
% Extract the biggest blob
allAreas = [measurements.Area];
[sortedAreas, sortingIndexes] = sort(allAreas, 'descend');
% Draw boundingbox arround biggest blob
Bigblob = measurements(sortingIndexes(1)).BoundingBox;
% Cut out biggest blob
DLim = imcrop(B,[Bigblob(1) Bigblob(2) Bigblob(3) Bigblob(4)]);
% Square image before resizing to maintain aspect ratio
Wblob = Bigblob(3);
Lblob = Bigblob(4);
if Wblob == Lblob
% do nothing
else
if Wblob > Lblob
DLim = padarray(DLim,[Wblob-Lblob 0],'pre');
else
DLim = padarray(DLim,[0 Lblob-Wblob],'pre');
end
end
% Resize - this result needs to replace the original image in the ORIGINAL imagedatastore ...
DLim = imresize(DLim,[1024,1024]);
end
Risposta accettata
Più risposte (1)
prasanth s
il 11 Giu 2018
0 voti
You can use augmented image datastore method to resize the image before training(matlab 2017b and after).
Categorie
Scopri di più su Deep Learning Toolbox in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!