Why do my rgb image is different and less defined than pcolor or imagesc outputs?
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Claudio Eutizi
le 11 Jan 2021
Commenté : Claudio Eutizi
le 13 Jan 2021
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.
0 commentaires
Réponse acceptée
Image Analyst
le 11 Jan 2021
Modifié(e) : Image Analyst
le 11 Jan 2021
The images do not have the same resolution. One has 224 rows while the other is smaller with around 125 rows. It looks like the smaller one may have been subsampled by taking the nearest row so it's not as smooth. Attach the data (image #5 I guess from your code) if you want further help.
By the way, normally pcolor just doesn't show the last row and column, as you can easily prove just by showing a small image like pcolor(magic(3)). So I think you must have done the resampling.
You can switch y axis order by doing
axis ij % Put origin at top, like for images and matrices.
axis xy % Put origin at bottom like for x-y graphs.
0 commentaires
Plus de réponses (2)
Claudio Eutizi
le 11 Jan 2021
3 commentaires
Image Analyst
le 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
le 12 Jan 2021
2 commentaires
Image Analyst
le 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
Voir également
Catégories
En savoir plus sur Blue dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!