Best practice: CWT image generating for Deep Learning images

8 views (last 30 days)
Hi,
I am looking some advice/best practice for genrating, formating and saving CWT images.
The task: I have ~5000 hours of EEG data recorded with lables at each thirty second interval. I would like to generate the CWT image of each 30 second window and save it. The image, should be devoide of a border, tics, axis lables and titles (i.e. just the spectogram image).
The Problem: I can generate an image with cwt(sig,fs), which is square, however includes all the extra bits I don't want, like borders:
load mtlb
w = cwt(mtlb);
cwt(mtlb,"bump",Fs)
I could extract the image out with a handle and save that way:
load mtlb
w = cwt(mtlb);
fig = cwt(mtlb,"bump",Fs); % Hide the output as it's quite long.
However, it quicly becomes apparent that the image data is not square, but rectangular.
load mtlb
w = cwt(mtlb);
fig = cwt(mtlb,"bump",Fs);
imshow(abs(fig)) % here's the same image in grayscale.
While I understand that the image is fundamentally rectangular, the skeewed aspect ratio becomes an unknown when ingested by a DL algoritum, to that end I would like to have all my images processed and "squared up" before being ingested. I wanted to know if anyone had any suggestions as to the best way to generate these CWT images in a manner that is easily ingested by DL networks, not disimilar to this paper, however the detail are light.

Answers (1)

Animesh
Animesh on 30 Jul 2024
Hey,
From what I can gather, you want to remove all the extra elements such as borders, axes, etc., and only save the image obtained from the "cwt" function, that too, in a square shape.
Here is something that can be done:
cwt(mtlb, 'bump', Fs)
% Remove other elements
set(gca, 'XTick', [], 'YTick', [], 'XColor', 'none', 'YColor', 'none');
set(gca, 'LooseInset', get(gca, 'TightInset'));
frame = getframe(gca);
img = frame.cdata;
% Resize the image to square
squareImg = imresize(img, [256 256]); % assumed image size to be 256x256, you can use hit and trial to find out the appropriate dimension as per your need
imwrite(squareImg, "squareImg.png");
Moreover, you can normalize the images to a consistent scale if needed for a deep learning model. For example, you may use the "rescale" function in MATLAB.
You can refer the following MathWorks documentation for information:

Products


Release

R2023b

Community Treasure Hunt

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

Start Hunting!