필터 지우기
필터 지우기

Half plotting problem of spectrogram

조회 수: 5 (최근 30일)
Sania Gul
Sania Gul 2022년 10월 27일
댓글: Sania Gul 2022년 11월 9일
I am producing spectrograms of 10 hour audio in chunks of 4 seconds, by using the "for" loop and storing it in a folder. But many of the spectrograms generated and saved are incomplete. Why it is so? and how I can stop this to happen
This problem is not for all spectrograms, only for 30% of the total.
  댓글 수: 2
Chunru
Chunru 2022년 10월 27일
Show your program.
Sania Gul
Sania Gul 2022년 10월 27일
Here is my code :)
clear all;
clc;
close all;
Fs=16000;
fs=Fs;
audio=[];
opening=0;
count =1;
% Load the source file
while 1
samples = [1+opening,count*Fs*4.12];% 16 time frames corresponds to 0.287 seconds interval
if samples(2)>540938091% total sample in audio train file
break
end
% if samples(2)>33152737% total sample in audio test file
% break
% end
audio=audioread('D:\Fazeel_Data\16KAll\TrainNoisy.wav',samples);
%Destination folder for storing images
Dest = 'D:\Fazeel_Data\Parula\TrainNoisyeePicsDup\';
% figure(1);
% spectrogram(audio,hann(512),256,512,Fs,'yaxis');
[Q,F,T] = spectrogram(audio,hann(512),256,512,Fs,'yaxis');
% Taking the log of Z-Axis (Brightness)
Q=Q(1:256,:);
F=F(1:256);
figure(2)
D=surf(T,F,log(abs(Q).^2));
colormap parula
shading interp
view([0 90])
axis tight
set(gca,'xtick',[])
set(gca,'ytick',[])
% print('AB','-djpeg','-r50');
% I=imread('AB.jpg');
% [a b c]=size(I)
export_fig AA.jpg -native -c[31 52 46 72]% top right bottom left
% resizing the image
I=imread('AA.jpg');
outputImage = imresize(I, [256,256]);
% imshow(outputImage);
export_fig AA.jpg -native -c[31 86 58 85]% top right bottom left
% imshow(outputImage);
% Copying the figure from current directory to Destination folder
% psource = 'D:\Fazeel_Data';
% pattern = 'AA.jpg';
% sourceFile = fullfile(psource, pattern);
[o p q]=size(outputImage)
imagefilename = sprintf('TrainNoisyee_%05d.jpg',count);
destFile = fullfile(Dest, imagefilename); % Or another name?
% copyfile(sourceFile, destFile);
imwrite(outputImage, destFile);
opening=samples(2);
count=count+1;
% pause(1);
end
end

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

채택된 답변

VBBV
VBBV 2022년 11월 7일
편집: VBBV 2022년 11월 7일
imwrite(outputImage, destFile,'Quality',"lossless");
It appears that some part of the image data is being lost during write operation. Try with name value argument specifying quality as lossless
  댓글 수: 6
VBBV
VBBV 2022년 11월 8일
편집: VBBV 2022년 11월 8일
I = imread('peppers.png');
imshow(I)
[r c] = size(I) % get the size of image
r = 384
c = 1536
if r == c
outputImage = imresize(I,[r c]); % this could be reason, change using scale value
elseif r < c
outputImage = imresize(I,[r+abs(c-r) c]); ;% this could be reason, change using scale value
elseif r > c
outputImage = imresize(I,[r c+abs(c-r)]);
end
outputImage = imresize(I,[120 c]); % see the difference with fixed row and col values
imshow(outputImage)
% imwrite(outputImage, destFile,"Quality",100); % switch back to normal mode
Note the difference when you use fixed numbers for rows and cols for all image sizes, Try with the higher or scaled values for rows and cols inside the imresize function and switch back to normal mode. May be some images have high resolution with large or different sizes,
Sania Gul
Sania Gul 2022년 11월 9일
Tnk u VBBV. The photo is compressed, however complete in your case. However, it is half drawn or incomplete in my case. I have to be restricted in defining the image size as my spectrograms are given as input to pix2pix network. Secondly I have generated 8000 spectrograms by the same set of instructions and only random 30% suffer from this problem. This may seems to be some issue in memory allocation by the processor as C drive is almost full. But anyways thanks for your time and efforts. I regard them high :-)

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Time-Frequency Analysis에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by