Why do my rgb image is different and less defined than pcolor or imagesc outputs?
Ältere Kommentare anzeigen
I want to automatically extract VGGish features 2D plots from an audio dataset and then save them in a folder.
here's my code I wrote for testing the output image:
datafolder = "F:\UrbanSound8K\structure1";
ads = audioDatastore(datafolder, ...
'IncludeSubfolders',true, ...
'FileExtensions','.wav', ...
'LabelSource','foldernames');
fs0 = 16e3;
[audioIn, fs] = audioread(ads.Files{5});
overlapPercentage = 84;
features = vggishFeatures(audioIn,fs,'OverlapPercentage',overlapPercentage);
features = features.';
im = ind2rgb(im2uint8(rescale(features)),colormap);
im = imresize(im,[224 224]);
imgLoc = fullfile(datafolder_vggishFeatures,char(ads.Labels(i)));
imFileName = strcat(char(ads.Labels(i)),'_',num2str(i),'.jpg');
imwrite(im,fullfile(imgLoc,imFileName));
The output turns out reversed on y-axis and with bad defined contours, unlike imagesc(features) and pcolor(features) outputs.
How can I solve this problem? Thank you.
Here you can find the output from the code previously written and the result of a pcolor command.

Akzeptierte Antwort
Weitere Antworten (2)
Claudio Eutizi
am 11 Jan. 2021
0 Stimmen
3 Kommentare
Image Analyst
am 11 Jan. 2021
You can zip them up. Make sure the number of elements of your audio file is a multiple of 224 (or 227 for AlexNet). But I'm not sure what image you're displaying with imagesc and what image you're displaying with pcolor (or why you're even using pcolor at all - I never do).
Claudio Eutizi
am 11 Jan. 2021
Image Analyst
am 11 Jan. 2021
Try this:
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 14;
files = dir('100*.wav')
fullFileName = fullfile(pwd, '100852-0-0-12.wav');
[y, fs] = audioread(fullFileName);
subplot(3, 1, 1);
plot(y, 'b-', 'LineWidth', 2);
% soundsc(y, fs);
grid on;
xlabel('Time', 'FontSize', fontSize);
ylabel('Signal Amplitude', 'FontSize', fontSize);
numOriginalSamples = size(y, 1)
numMultiplesOf224 = numOriginalSamples / 224 % Hopefully it's an integer.
% Make output vector
vec = zeros(1, ceil(numMultiplesOf224) * 224); % Initialize to a multiple of 224
% Insert sound signal
vec(1:numOriginalSamples) = y;
% Reshape to an image.
image224 = reshape(vec, 224, []);
subplot(3, 1, 2);
imshow(image224, 'ColorMap', jet(256));
axis('on', 'image');
caption = sprintf('Original image is %d rows by %d columns', size(image224, 1), size(image224, 2));
title(caption, 'FontSize', fontSize);
% Resize to 224 x 224
numNewSamples = 224 * 224
xq = linspace(1, numOriginalSamples, numNewSamples);
vec = interp1(1:numOriginalSamples, y, xq, 'spline');
% Reshape to an image.
image224 = reshape(vec, 224, 224);
subplot(3, 1, 3);
imshow(image224, 'ColorMap', jet(256));
axis('on', 'image');
caption = sprintf('Resized image is %d rows by %d columns', size(image224, 1), size(image224, 2));
title(caption, 'FontSize', fontSize);

Claudio Eutizi
am 12 Jan. 2021
0 Stimmen
2 Kommentare
Image Analyst
am 12 Jan. 2021
Tell me what folder structure and files do I need to have to run your code. Also, I don't seem to have the vggishFeatures() function. Is it in a special toolbox that I don't have? What does this say:
which -all vggishFeatures
Claudio Eutizi
am 13 Jan. 2021
Kategorien
Mehr zu Multirate Signal Processing finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
