how to convert signal into 2D image gray scale

Risposte (1)

Ameer Hamza
Ameer Hamza il 29 Ott 2020
The documentation shows that if you call cwt(): https://www.mathworks.com/help/wavelet/ref/cwt.html with an output argument, then it will return a 2D matrix. You can take the absolute value of the matrix and display it as a grayscale image.

15 Commenti

Thank you for reply , when I use it I got this error
Error using mat2gray
Expected input number 2, LIMITS, to be an array with number of elements equal to 2.
The output of cwt should already by 2D matrix. You don't need to call mat2gray. You might need to rescale it to display it properly
M = cwt(input_signal);
M = abs(M);
M = rescale(M, 0, 1);
imshow(M)
but in this case I will get color image not gray
I don't have the toolbox so cannot run the code, but can you show the output of
M = cwt(input_signal);
M = abs(M);
size(M)
If it is a 2D matrix, then imwhow will automatically show a grayscale image.
mat2gray() is an older routine that is suitable for rescaling data to the range [0 1]
However, you would not typically pass a second argument to mat2gray, and when you do pass a second argument it must be a vector of two values that is the range to scale to.
imshow() of a 2D array will not be color, but you might want to
imshow(M, [])
Thank you for reply Dear @Ameer Hamza I got this error
Error using cwt (line 300)
Expected input to be a vector.
load('ECGData.mat');
data=ECGData.Data;
ARR=data(1:30,:);
M = cwt(ARR);
M = abs(M);
size(M)
my main code
this,
%program to create CWT Image database from ECG signals
load('ECGData.mat'); %load ECG data
data=ECGData.Data; %Get Signal Values in data
labels =ECGData.Labels ; %Get Labels in labels
ARR=data(1:30,:); %Taken first 30 recordings
CHF=data(97:126,:);
NSR=data(127:156,:);
signallength=500;
%Defining filters for CWT with amor wavelet and 12 filters per octave
fb=cwtfilterbank('signalLength',signallength,'Wavelet','amor','VoicesPerOctave',12);
mkdir('ecgdataset'); %Main Folder
mkdir('ecgdataset\arr'); %Sub Folder
mkdir('ecgdataset\chf');
mkdir('ecgdataset\nsr');
ecgtype={'ARR','CHF','NSR'};
%Function to convert ECG To Image
ecg2cwtscg(ARR,fb,ecgtype{1});
ecg2cwtscg(CHF,fb,ecgtype{2});
ecg2cwtscg(NSR,fb,ecgtype{3});
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
this is the fun
function ecg2cwtscg(ecgdata,cwtfb,ecgtype)
nos=10;%number of signals
nol=500; %signal length
colormap=jet(128);
if ecgtype=='ARR'
folderpath=strcat('D:\ecgdataset\arr\');
findx=0;
for i=1:30
indx=0;
for k=1:nos
ecgsignal=ecgdata(i,indx+1:indx+nol);
cfs=abs(cwtfb.wt(ecgsignal));
im=ind2rgb(im2uint8(rescale(cfs)),colormap);
filenameindex=findx+k;
filename=strcat(folderpath,sprintf('%darr.jpg',filenameindex));
imwrite(imresize(im,[227 227]),filename);
indx=indx+nol;
end
findx=findx+nos;
end
elseif ecgtype=='CHF'
folderpath=strcat('D:\ecgdataset\chf\');
findx=0;
for i=1:30
indx=0;
for k=1:nos
ecgsignal=ecgdata(i,indx+1:indx+nol);
cfs=abs(cwtfb.wt(ecgsignal));
im=ind2rgb(im2uint8(rescale(cfs)),colormap);
filenameindex=findx+k;
filename=strcat(folderpath,sprintf('%dchr.jpg',filenameindex));
imwrite(imresize(im,[227 227]),filename);
indx=indx+nol;
end
findx=findx+nos;
end
elseif ecgtype=='NSR'
folderpath=strcat('D:\ecgdataset\nsr\');
findx=0;
for i=1:30
indx=0;
for k=1:nos
ecgsignal=ecgdata(i,indx+1:indx+nol);
cfs=abs(cwtfb.wt(ecgsignal));
im=ind2rgb(im2uint8(rescale(cfs)),colormap);
filenameindex=findx+k;
filename=strcat(folderpath,sprintf('%dnsr.jpg',filenameindex));
imwrite(imresize(im,[227 227]),filename);
indx=indx+nol;
end
findx=findx+nos;
end
end
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
data set
I got from this code color image
I need it grayscale imgae
could you help me
cwt() only accepts vectors, not images. For grayscale images use cwtft2()
If the code is designed for color images, then take your grayscale images and repmat(GRAYSCALE,[1 1 3]) to get a color image and process it through the code.
However, the code you posted is for processing 1D EEG signals, not for images of any kind.
Mathworks does not provide any equivalent of cwtfilterbank for 2D.
thank you gays I sloved it , I just replace the
ind2rgb to ind2gray
Hello , when I run the above code I got 3 channel for each image , my quastion how can I get 1 channel for each image
You can use rgb2gray() to convert 3 channels to 1.
how can I use it with my code above , thank you
I used but my data sitl 3 channel

Accedi per commentare.

Prodotti

Release

R2019b

Richiesto:

il 29 Ott 2020

Community Treasure Hunt

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

Start Hunting!

Translated by