sending and receiving IMAGE using serial port(USB to serial)

6 次查看(过去 30 天)
Hi friends,
Actually I have an image which need to be transferred via serial port. As my laptop dosent contain serial port i am using USB to serial convertor.I am sending image from one computer other using two USB to serials and null modem. I am doing this for testing purpose and later null modem will be replaced by 8051 controller. I wrote a code for transferring but i am unable to receive data proper control. Please check the below code.
For Transfering
if true
SendData=serial('COM1','BaudRate',256000);
fopen(SendData);
[rows,columns]=size(Encryptedimage);
for k=1:3
for i=1:rows
for j=1:columns
data=num2str(EncryptedImage(i,j,k));
fprintf(SendData, '%c' , '*');
fprintf(SendData, '%s',data);
end
end
end
fclose(SendData);
delete(SendData);
clear SendData;
end
For receiving
if true
recData=serial('COM2','BaudRate',256000);
fopen(recData);
while(1)
Input1=fread(receiveTemp)
if(isempty(Input1))
continue;
else
disp('Value received')
for k=1:3
for i=1:rows
for j=1:columns
Input1=char(Input1);
Input1=sscanf(Input1, '%d');
EncryptedImage1(i,j,k)=Input1;
Input1=fread(receiveTemp);
end
end
end
end
if(i==rows & j==columns & k==3)
break;
end
end
end
Now problem is while receiving Input1 is getting around 120 values at a time. please help me in rectifying this issue.
  34 个评论
Walter Roberson
Walter Roberson 2018-2-18
Use several steps:
  1. read the biomedical image in, which is a step that is independent of any image processing you plan to do
  2. Do whatever image processing is appropriate for your biomedical image for whatever purpose you need, which is a step that is independent of reading the image and is independent of any plans to transmit the image
  3. if the processed image is not already uint8, use typecast() to make a byte stream out of it. This is a step that is independent of reading the image and is independent of whatever image processing you did.
  4. reshape your now uint8 image to a vector
  5. transmit the uint8 vector by LED technology -- which is a step that is independent of everything having to do with calculating which uint8 are going to be transmitted

请先登录,再进行评论。

回答(1 个)

Walter Roberson
Walter Roberson 2013-4-26
Replace
[rows,columns]=size(Encryptedimage);
with
[rows,columns,bands]=size(Encryptedimage);
In the form of size() that you were using, "columns" would be set to the real columns times the number of bands.
  2 个评论
srikanth
srikanth 2013-4-26
Thanks for correcting me. But still this didnt rectified my problem of serial communication. When i am transferring values to hyper terminal i can see values continuously. But when using Matlab at reception side 'Input1' variable is showing lots of values at a time and matlab is giving error dimension mismatch. Maybe i feel there is some synchronization problem between transition and reception.How to rectify this issue?
Walter Roberson
Walter Roberson 2013-4-26
You know that fread() without a size parameter will try to read until the buffer is full ? http://www.mathworks.com/help/matlab/ref/serial.fread.html
You should also be considering using the 'precision' parameter of fread().
You might want to re-think why it is that you are using the formatted-data function fprintf() to send the data, but are using the binary-data function fread() to read it.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Read, Write, and Modify Image 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by