Undesirable size of resized images
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Geoff Hayes
2022-1-21
@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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Convert Image Type 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!