Undesirable size of resized images
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Daeyeon Koh
el 12 de En. de 2022
Respondida: Geoff Hayes
el 21 de En. de 2022
Hi.
I transformed audio files to spectrogram images and saved them in the folder.
To apply the images to open source MATLAB deep learning code, I resized them in [224 224 3].
However, the size of stored resized images was an undesirable size: [656 875 3]
How can I store images resized as desired?
Audio_Address = 'C:\Users\KOH\Desktop\MATLABcode\Audiofiles_RabbitLab';
SPTRGM_Address = 'C:\Users\KOH\Desktop\MATLABcode\RL_SpectrogramData';
Directory0 = dir(fullfile(Audio_Address,'RabbitSimul_0.0cc*.wav'));
Directory00 = dir(fullfile(SPTRGM_Address,'RabbitSimul_0.0cc*.jpg'));
ImageData_Address00 = 'C:\Users\KOH\Desktop\MATLABcode\RL_SpectrogramData(resize)\00';
windowSize = 256;
windowOverlap = [];
freqRange = 1000:20000;
for i = 1:numel(Directory0)
F = fullfile(Audio_Address,Directory0(i).name);
[y,Fs] = audioread(F);
endtime = numel(y)/(2*Fs);
t = 1/Fs:1/Fs:endtime;
AudioData{i}=y(:,1);
OGspectrogram=spectrogram(AudioData{i}, windowSize, windowOverlap, freqRange, Fs, 'yaxis');
spectrogram(AudioData{i}, windowSize, windowOverlap, freqRange, Fs, 'yaxis');
saveas(gcf,fullfile(SPTRGM_Address,sprintf('RabbitSimul_0.0cc_%d.jpg',i)));
end
for i = 1:numel(Directory00)
F = fullfile(SPTRGM_Address,Directory00(i).name);
SPTRGMimage{i,1}=imread(F);
Mod_SPTRGMimage{i,1}=imresize(SPTRGMimage{i,1},[224 224]);
imshow( Mod_SPTRGMimage{i,1});
saveas(gcf,fullfile(ImageData_Address00,sprintf('RabbitSimul_0.0cc_%d.jpg',i)));
end
imds = imageDatastore(SPTRGM_Address,'IncludeSubfolders',true,'LabelSource','foldernames');
img = readimage(imds,1);
size(img)
ans =
656 875 3
0 comentarios
Respuesta aceptada
Geoff Hayes
el 21 de En. de 2022
@Daeyeon Koh - I think that you are saving the figure rather than the image that is displayed in the figure to the file
saveas(gcf,fullfile(ImageData_Address00,sprintf('RabbitSimul_0.0cc_%d.jpg',i)));
and so it makes sense that the size is not what you expect it to be? I suspect if you open the image, you will see the axes, labels, and other components of the figure. Is this intentional or do you want to be saving the image Mod_SPTRGMimage{i,1} to file as
imwrite(Mod_SPTRGMimage{i,1},fullfile(ImageData_Address00,sprintf('RabbitSimul_0.0cc_%d.jpg',i)));
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Convert Image Type en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!