How to convert jpeg file to RAW10 data format?

Hello,
Is there a way to convert an image file (e.g. jpeg format) to RAW10 data format using MatLab?
Thank you.

 Réponse acceptée

Guillaume
Guillaume le 3 Avr 2018

0 votes

While yes, as Walter says, you potentially could write a converter, it seems to be the opposite workflow to what people normally do. So, what would be the reason to want to do this?
There are a few technical considerations to bear in mind as well:
  • your image is probably 8-bit per pixel. The RAW10 is 10-bit per pixel. So you'll always have the two highest bits wasted. If the image was initially RAW10, you're never going to recreate the additional 2 bits of information that were lost.
  • RAW10, like all raw formats assumes the decoder knows what sensor the image corresponds to. Therefore, the RAW10 format does not include any information about the image such as width and height and bayer pattern. The image is just one long line of pixels. It's up to the decoder reshape that into a rectangle of the right size and to remove potential padding pixels (if the number of columns is not a multiple of 4).
  • If the image is colour, then the pixels in RAW10 needs to be encoded using a bayer pattern. There are several possible bayer patterns (GBRG, GRBG, BGGR, RGGB) so you'd have to chose the one that matches your sensor/decoding software. An additional problem is that while matlab has a function to decode bayer patterns it does not have one for encoding into them, so you'd have to write your own.
Once the image has been bayer encoded it's easy to convert it to RAW10. I can write the code for that if really needed (but not the bayer encoding).

5 commentaires

Additional technical information about one particular RAW10 vendor: https://www.raspberrypi.org/forums/viewtopic.php?f=43&t=44918
The person doing the work figures the bayer pattern might be CYYM
Mark Allen Lagaya
Mark Allen Lagaya le 4 Avr 2018
Modifié(e) : Mark Allen Lagaya le 4 Avr 2018
The reason I need to convert a jpeg to RAW10 format is that the input to my testbench requires a RAW10 format.
Yes the image I have is 8bits per color or 24bits per pixel, colored, which is in jpeg format. So I need to encode it first using bayer pattern, then arrange it to follow the RAW10 format.
Guillaume
Guillaume le 4 Avr 2018
"So I need to encode it first using bayer pattern, then arrange it to follow the RAW10 format"
It's a bit more complicated than that. You need to know which bayer pattern and which image size your testbench is expecting. As said, these are not stored in the RAW10 format and there is no way infer them once the image is encoded in RAW10. So the writer (the matlab code) and the reader (your testbench) must use the same convention. So do you know what your testbench is expecting?
Also note, that by necessity converting an RGB image to a bayer pattern is lossy. You'll lose 2/3 of the information. If the image originally came from a bayer pattern, then that lost information is probably redundant.
Guillaume
Guillaume le 4 Avr 2018
Modifié(e) : Guillaume le 4 Avr 2018
The person doing the work figures the bayer pattern might be CYYM
Actually, you can see later on that they figure out it's BGGR. That makes more sense, I've never heard of a sensor with CMY filters.
Each sensor will have its own pattern and again, it's not something encoded in the raw10 format. It's up to the reader to know what it is and decode the image accordingly.
Ah, I did not look on the right part of the page for the continuation indicators. There is too much information in the discussion for me to process well at the moment, as I am not familiar with a number of parts of what is being discussed -- but it is clear that at least for that device that reversing a RAW10 would not be easy.
I think we would need more information about the device being used on the test bench.

Connectez-vous pour commenter.

Plus de réponses (1)

Walter Roberson
Walter Roberson le 3 Avr 2018

0 votes

Yes, it should not be bad if you follow the file format description of https://developer.android.com/reference/android/graphics/ImageFormat.html#RAW10
There is no obvious file header for RAW10, just data. I am not sure how the size information is stored.

3 commentaires

Hi Walter,
I understand the file format of RAW10 but I was hoping if there is a tool or a code using MatLab that can convert an RGB format to RAW10 format and will output as a bitstream in a text file.
I was only able to see the pixel values of a whole image using the impixel command but I don't have an idea if there is a way to convert that pixel values to RAW10.
Any input? Thank you.
Guillaume
Guillaume le 3 Avr 2018
a bitstream in a text file
The two things are contradictory. What do you mean exactly?
Sorry for the confusing statement. What I have is a jpeg format and I'm looking for means to convert that to RAW10. The RAW10 format file will be used as an input to a testbench.

Connectez-vous pour commenter.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by