Converting binary to image file

36 visualizaciones (últimos 30 días)
Özgür Alaydin
Özgür Alaydin el 2 de Ag. de 2022
Respondida: Walter Roberson el 3 de Ag. de 2022
Hello All
I have a binary text file and i want to convert it to image file. It can be png, jpeg or whatever.
I have used the following code but i did not understand the error. Please help me
reconstructed = reshape(typecast(uint8(bin2dec(char(reshape('sobel', 8, [])+'0').')), 'uint8'), 100);
imshow(reconstructed);
title('reconstructed')
  1 comentario
Walter Roberson
Walter Roberson el 2 de Ag. de 2022
reshape('sobel', 8, [])
That asks that the character vector ['s' 'o' 'b' 'e' 'l'] get reshaped. You do not show any code that reads the file.
I do not recommend cramming that many operations in one line. Remember that the time the programmers spend reading and writing the code is likely to be much greater than any execution time saved.

Iniciar sesión para comentar.

Respuestas (2)

Constantino Carlos Reyes-Aldasoro
Constantino Carlos Reyes-Aldasoro el 2 de Ag. de 2022
You are mixing many things.
If you use 'sobel' between single quotes you are using a string with the characters s o b e l.
If you have a file called 'sobel.txt' you should first read that file and store the values in a variable, which you will later use to create your image.
If you want to save an image file, you first need to have it in matlab, ideally you can then display it to check it makes sense and then you can print it to a png or whatever you want.

Walter Roberson
Walter Roberson el 3 de Ag. de 2022
The contents of the file are already characters. You do not need to +'0': you only +'0' if the content is numeric 0 and 1 rather than character '0' and '1'

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