¿Cómo creo una imagen en escala de grises a partir de datos que no son de imagen?

I have a array containing data. This array contains only image data/ or it can be just random data. No header information is available. So writing this to a file and making its extension as jpg is not going to work. Can someone please recommend a library that would do this for me.

Any language that isnt a scripting language is ok. Any environment. I would prefer if its in C/Java/Matlab.

preguntado el 08 de noviembre de 11 a las 12:11

"I have a array containing data." <- which language is your array in !!! PHP / C / Java etc etc ?? -

its in java. but its a very small program. If you know a library in C++ i will write it in C++. -

More importantly, what format is the data in the array? Is planar, or interleaved? How many channels? What is the bit depth of each channel? How do you represent each sample? Signed or unsigned? Without knowing all of this information, it is impossible to answer your question. It is too vague. -

cant i create a header as mentioned in en.wikipedia.org/wiki/BMP_file_format and append the data to it ? -

Please explain in your question what you are trying to do. You have a bunch of unknown data and are trying to find out whether it represents an image? -

1 Respuestas

If you have your array in MATLAB (let's say it's in a variable called im), then you can just type

imwrite(im, 'myfilename.bmp', 'bmp')

and your array will be written to a .bmp file. You can choose from a number of other common formats too. See the documentación para imwrite.

You can even write random data in this way:

a = rand(100,100);


respondido 08 nov., 11:18

hi but the problem is iam not sure weather this array contains true image data. It can also be just random data as well. - user574183

As long as your array is of class double, uint16, uint8 or logical, then whatever it contains MATLAB will write it out as an image file. It's all just numbers. If it's "true image data", you'll get an image file that looks interpretable when opened; if it's "just random data", you'll get an image file that looks random when opened. - Sam Roberts

are u sure i will be able to open a image created with random data in a picture viewer program ? - user574183

Yes. Added an example above to illustrate. - Sam Roberts

Surely the image width, at the very least would have to be known up front otherwise the image will be rendered wrongly. Plus if this array happens to be in a different format this is not going to fly, i.e. valid image (e.g. compressed JPEG) data may appear as if it were random when it is not. The question is far too vague. - Paul Ruane

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.