Convert Signal into a image for deep CNN input
16 views (last 30 days)
Show older comments
CHRISTIAN COSSU
on 7 Apr 2023
Commented: CHRISTIAN COSSU
on 10 Apr 2023
Hi,
I'm doing a work on creating a deep CNN network that has a multi input of images. In particoular electrograms in time domain, sswt, hht, cwt.
How can i convert a 500x1 signal into a 100x100 matrix that will become an image with significant info input for the CNN?
I thought something like this
M=zeros(100,100);
y=floor(mean(reshape(sig,[5 100]))); %returns the mean of 5 elements along the vector of the signal
for i=1:size(M,1)
for j=1:size(M,2)
M(i,j)=y(i);
end
end
figure
image(M)
f=getframe;
p=f.cdata;
I=imresize(p,[100 100]);
imwrite(I,'filename.jpeg')
%ready to be saved
%or in a easier way, but i don't know if this will have useful info for the
%CNN
plot(M)
f=getframe;
p=f.cdata;
I=imresize(p,[100 100]);
imwrite(I,'filename.jpeg')
These are not the saved images, all of the parameters of them, like colormap, caxis and etc will be tweaked later.
Thanks in advance.
0 Comments
Accepted Answer
Abhishek
on 10 Apr 2023
Hi Christian,
I understand you want to know how to convert an ECG signal into a 2D image to be used as input for a CNN model.
However, since you have not provided information regarding the signal or database you are using and intended objective for the model, I assume it's likely to deal with the cardiac dynamics of ECG, such as Arrhythmia, Normal Sinus or any other rhythm. For CNN to learn the graphical deflections, or any abnormal parameters, the best option would be sample ECG for a cycle (for example, between a R-R interval or a QRS complex). Then you can either save it as a time series or convert it to spectrogram for frequency analysis, depending upon your use case.
You can save the plots programmatically either by using exportgraphics or first getimage and then using imsave.
You can refer to following examples to read about popular datasets used for similar applications: -
3 Comments
Abhishek
on 10 Apr 2023
Prima facia, this should work with the later image type that you posted in the question.
However, given the size of input data, use of datastores would be suggested to reduce complexity of the CNN. There are built-in datastores for deep learning applications which are well suitable for regression tasks. You can use 2-D image sequence and can also specify parallel or multi-GPU training.
Please go through the following documentation to know more about datastores:-
More Answers (0)
See Also
Categories
Find more on AI for Signals and Images in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!