Conversion of (129x7 complex double) to an Image

조회 수: 6 (최근 30일)
Muhammad
Muhammad 2023년 2월 4일
댓글: DGM 2023년 2월 7일
I have a variable s (129x7 complex double). I want to save it as an image. I have tried many ways but I can't save it.
for k=1:size(cm,2)
s = spectrogram(cm(:,k));
save(['Spectro_Subj' num2str(h) '_channel' num2str(i) '_window' num2str(k) '.mat'],'s')
end
  댓글 수: 2
DGM
DGM 2023년 2월 4일
Typical image formats (BMP,PNG,JPG) support unsigned integer (or logical) datatypes. Some (TIFF) can be wrangled into supporting floating-point numeric data, but you shouldn't expect anything to be able to read the file. No image format that I know of supports complex-valued numeric data. You may be able to store the components of the data in separate images (real and imag), or perhaps it may suffice to reduce it to magnitude only.
Long story short, if you have arbitrarily-scaled complex data and you want to save it as a typical image format, you'll have to decide on a means of preserving scale information, and you'll have to decide which components of the complex data you want to keep or how you want to encode them into a single real-valued integer array (perhaps magnitude/phase can be encoded as intensity/hue?).
Walter Roberson
Walter Roberson 2023년 2월 4일
Tiff supports ComplexIEEEFP. However MATLAB's interface to libTiff does not support that.

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

채택된 답변

Image Analyst
Image Analyst 2023년 2월 6일
편집: Image Analyst 2023년 2월 7일
for k=1:size(cm,2)
spectrogram(cm(:,k));
baseFileName = sprintf('Spectro_Subject %d_channel %d_window %d.png', h, i, k);
fullFileName = fullfile(pwd, baseFileName);
fprintf('For k = %d, saving "%s".\n', k, fullFileName);
exportgraphics(gca, fullFileName);
end
  댓글 수: 8
Muhammad
Muhammad 2023년 2월 7일
@Image Analyst thank you so much i will. In the mean time as you can see i segment the signal into 3.5s frame windows, i need to have time (0-3.5s) on x axis and Frequency on Y axis. Currently i am just getting samples and normalized frequency. please have a look into the below attachement.
DGM
DGM 2023년 2월 7일
Note the only reason why I don't use exportgraphics() isn't because saveas() is better. I just run an older version, so I can't verify my example with something I can't run.

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

추가 답변 (2개)

Walter Roberson
Walter Roberson 2023년 2월 4일
you could use the tiff gateway and write the imaginary component as unassociated alpha. There is an example at
https://www.mathworks.com/help/matlab/ref/tiff.html#mw_a2efd938-557e-41ad-925b-64f84a51f07b
The difference is that you would specify 2 samples per pixel instead of 4, and you would use IEEEFP sample format.
There is a file exchange contribution for writing floating-point tiff that is worth studying.
So... you would be able to use an image file, and use floating point samples, and write two channels.
What you should not expect is for any other program to be able to produce a readable image from the data

DGM
DGM 2023년 2월 4일
이동: Image Analyst 2023년 2월 6일
Are you sure you don't want to just save a graphical representation (i.e. a plot)?
% some fake test signal
fs = 1000;
t = 0:1/fs:2-1/fs;
y = chirp(t,100,1,200,'quadratic');
% plot the spectrogram
spectrogram(y,100,80,100,fs,'yaxis')
colormap(parula(256))
% save the figure
saveas(gcf,'myplot.png')
If so, there are many different ways it can be represented.
  댓글 수: 1
Muhammad
Muhammad 2023년 2월 6일
이동: Image Analyst 2023년 2월 6일
thanks alot that is what i was looking for.

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

카테고리

Help CenterFile Exchange에서 Image Data Workflows에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by