Why do my rgb image is different and less defined than pcolor or imagesc outputs?

조회 수: 3 (최근 30일)
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.

채택된 답변

Image Analyst
Image Analyst 2021년 1월 11일
편집: Image Analyst 2021년 1월 11일
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.

추가 답변 (2개)

Claudio Eutizi
Claudio Eutizi 2021년 1월 11일
Thank you for your answer.
How can i attach an audio file? ads.Files{5} is an audio file.
However, I need 224x224 images because of the input layer of the NN I'm using for Deep Learning and I would like to obtain images with the same resolution and smoothness as the pcolor output.
  댓글 수: 3
Claudio Eutizi
Claudio Eutizi 2021년 1월 11일
Here's the audio file in the zip.
Here's both imagesc (right) and pcolor (left) outputs. They're the same.
How can I obtain 224x224 png or jpg files with this resolution?
figure;
subplot(1,2,1); imagesc(features);
axis ij
axis xy
subplot(1,2,2); pcolor(features); shading flat;
Image Analyst
Image Analyst 2021년 1월 11일
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
Claudio Eutizi 2021년 1월 12일
It works with the audio file.
But I need this way of reshaping for VGGish features images like the ones i previously attached here, and not for audio files.
How can I do it?
Thank you so much for the help.
  댓글 수: 2
Image Analyst
Image Analyst 2021년 1월 12일
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
Claudio Eutizi 2021년 1월 13일
C:\Program Files\MATLAB\R2020b\toolbox\audio\audio\vggishFeatures.m
It's a function that's in the Audio Toolbox.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Blue에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by