Convert signal to image??

Hy,
I read analog signal from external device "ECG" by serial rs232 connection, I need to cut this signal to stored as image by code in matlab because my m file program is depended of Image processing not signal processing and my project is about image processing, so I can't write my program by signal processing.
my problems is:
1- read the signal from serial port.
2- convert this signal to image, and stored this image in current folder of matlab.
3- Please, I need answers for the last problems as codes not as Block. because I work at M file.
thanks for everyone try to help me,

Answers (2)

Image Analyst
Image Analyst on 5 Nov 2012

1 vote

You could use reshape() to turn your 1D signal into a 2D image, though I don't know if that would help. Anyway, many or most functions in the Image Processing Toolbox work on 1D images (just a single row or column of "pixels") so you may not need to do anything at all with your 1D ECG signal..

12 Comments

Firstly, thanks to help my...
I'm search in Matlab help for reshape() code, I conclusion the code is to reorder the matrix. That true?
You tell my the signal is as 1D and we can applied codes of image processing on it. That true?
my program is that:
a=serial('COM3', 'BaudRate', 9600);
fopen (a)
data = fscanf (a);
b=imread('normal.png');
a=rgb2gray(a);
b=rgb2gray(b);
a=im2bw(a);
b=im2bw(b);
%per diff between a and b
perab = sum(xor(a(:), b(:)) ~= 0) / numel(a);
fclose (s)
delete (s)
clear s . . .
the last code can applied for the signal from ECG? and the code is enough to read signal from serial port? And if you find errors in codes corrected me, please
I know, my questions is many, so many,, but that is to my final project in University, and I need to your help, Please
Thanks again...
Your line
a=rgb2gray(a);
is trying to convert the serial port object "a" to grayscale.
We are going to need a look at your normal.png file. Please upload it and tell us the URL; see http://www.mathworks.com/matlabcentral/answers/7924-where-can-i-upload-images-and-files-for-use-on-matlab-answers
Thanks Walter for your comments, the code a=rgb2gray is for image in my PC but I forget to delete it, I'm sorry
my code is:
a=serial('COM3', 'BaudRate', 9600);
fopen (a)
data = fscanf (a);
b=imread('normal.png');
b=rgb2gray(b);
b=im2bw(b);
%per diff between a and b
perab = sum(xor(a(:), b(:)) ~= 0) / numel(a);
fclose (s)
delete (s)
clear s . . .
I need to compare between my image in PC and the signal coming from ECG device by serial port, "find percentage different"
I write code to compare between 2 image in PC, and to do that: 1- convert image to gray. 2- and then convert to binary image. 3- apply the code "perab = sum(xor(a(:), b(:)) ~= 0) / numel(a);"
but I need to do that with signal coming from serial port after convert it to image?
my image normal.png is as any image from ECG device; as:
thanks for trying help me...
Your line
perab = sum(xor(a(:), b(:)) ~= 0) / numel(a);
is trying to process the serial port object.
this line to find percentage different between my image in PC and the signal coming from serial port after converted to image
The problem is that a(:) is the serial port object, not data read from the serial port object.
OK; but what I need to find the solution for this problem?
I think if I found solution to convert the signal to image "Deal with signal as a image", I will skip all of problems, what your suggestion? Please
You will need to fgets() or fscanf() enough data to represent the signal.
If you are reading ECG data from the serial port rather than an image, then you will need to plot the ECG data using exactly the same routine and settings and size as was used to create your normal.png file, and then you will need to take a snapshot of that graph and compare the information in the snapshot to b.
It would probably be much simpler if you had the data used to create normal.png rather than the plotted version of the data.
your comments answer many question for me, thanks very much to you Walter, thanks a lot...
one other question, Please
Is there a code work as snapshot automatically? I mean when I plot the signal I need code to work as snapshot, but automatically
getframe()

Sign in to comment.

Use spectogram functions of signal to convert as an image. I guess you need this method to process images using deep learning. It should be noted that you must segment the signal before applying it to the network. Use these functions:
spectrogram(1DSignal)
pspectrum(1DSignal,FS,'spectrogram')
wvd(1DSignal,FS,'smoothedPseudo')

4 Comments

Back in 2012 when the question was asked, the Deep Learning functions did not exist.
Also, the person specifically asked not to use signal processing functions because they were working on an image processing problem.
Dear Walter
Agreed, I had not looked at date of the comment. However this can be done for 2017 or highr. Calm down.
wvd() was introduced in R2018b, in the Signal Processing Toolbox. pspectrum needs R2017b (and so would not work in R2017a)
A lots happened since 2012. I graduated. I worked in different fields until I ended as a lift engineer. I got married. I moved to the UK and now still working as a lift engineer in the UK and had nothing to do with image processing and matlab in general. I even reset my password to write this comment. I remember I solved my issue at the time anyway and can’t remember how. Maybe the positive points now I have a good English not rubbish one. And I don’t use this picture as a profile picture anymore. I do have lots better lol.
Thanks guys it’s nice to have a notification for something you asked from a long time

Sign in to comment.

Categories

Find more on Communications Toolbox in Help Center and File Exchange

Asked:

on 5 Nov 2012

Commented:

on 7 Feb 2021

Community Treasure Hunt

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

Start Hunting!