How to convert jpg matrix to binary matrix

1 visualización (últimos 30 días)
Bence Salanki
Bence Salanki el 7 de Oct. de 2017
Respondida: Walter Roberson el 10 de Oct. de 2017
Hi!
I would like to send an image with a LED, and to do that first I need to read the .jpg image with imread(), but here as a result I get a matrix with decimal elements. Later, for sending the image I will need only binary elements (1-LED is ON, 0-LED is OFF). I was thinking of using the dec2bin() conversion and the result I can store in a new matrix as a string (since it has more elements) and at the sending I just run through each string with a loop and turn the on/off depending on the 0/1 values, but the problem is that after the dec2bin() conversion I will get different sized strings and the receiver shouldn't know these sizes. Is there any other solutions for this problem?
Thank you so much.

Respuestas (3)

Star Strider
Star Strider el 7 de Oct. de 2017
Try the im2bw or the imbinarize functions in the Image Processing Toolbox. See the documentation on them for necessary details.
  1 comentario
Bence Salanki
Bence Salanki el 7 de Oct. de 2017
Editada: Bence Salanki el 7 de Oct. de 2017
Thank you very much for your answer. The thing is that I don't want to loose the color information and the functions that you suggested are converting the image into black&white.

Iniciar sesión para comentar.


Image Analyst
Image Analyst el 8 de Oct. de 2017
Here's one approach:
for k = 0 : 255 % Show what happens for every gray level.
thisString = dec2bin(k);
string8 = '00000000';
string8(end-length(thisString)+1:end) = thisString
end
Now all the pixels will be 8 characters, with leading zeros if necessary.

Walter Roberson
Walter Roberson el 10 de Oct. de 2017
dec2bin(k, 8)
gives a fixed number of outputs.

Categorías

Más información sobre Convert Image Type en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by