I'm trying to convert color image from .raw format into .jpg or .png format, I used ImageMagick with the following command prompt code:
convert -size 768X576 -depth 8 rgb:my_image.raw my_image.jpeg
It is work successfully to convert the image into jpeg format, but with some problems which are: 1- The resulted image is gray and not colored. 2- The resulted image is subdivided into 9 images as a grid of small images repeated.
When I change rgb
into gray
, return me 3 separated gray image with different in lighting conditions from darker to lighter.
I'm necessary need to convert the image format, can anyone please help me how can I edit the code or also any other software that able to open the image, I tried very software but they are usefulness, I use windows 10.
I tested it with my own raw input image, and it's working fine.
You may be using a wrong version of ImageMagick.
I downloaded the version: ImageMagick-7.0.8-49-Q8-x64-static.exe
from https://imagemagick.org/script/download.php.
In the version I downloaded, the convert command is magick.exe
and not convert
.
The following command is working:
magick.exe -size 768x576 -depth 8 rgb:my_image.raw my_image.jpeg
.
I prefer using FFmpeg
for format conversion.
You can download it from https://ffmpeg.zeranoe.com/builds/
Select:
Version: stable (current version is 4.1.3).
Architecture: Windows 64-bit
Linking: static.
Extract the zip file, you only need ffmpeg.exe
.
For converting the raw
file to jpeg
using FFmpeg
you can use the following command:
ffmpeg -y -video_size 768x576 -pix_fmt rgb24 -i my_image.raw -pix_fmt yuvj444p my_image.jpeg
Assuming your raw file format is "chunky" RGB (ordered: r,g,b,r,g,b,r,g,b...), make sure the file size is 768*576*3
= 1,327,104 Bytes.
Just to make sure, the problem is not in your input file...
You can create an synthetic input raw
image using FFmpeg
and convert the result to jpeg
:
Create synthetic input:
ffmpeg -y -f lavfi -i testsrc=duration=1:size=768x576:rate=1 -pix_fmt rgb24 -f image2 test_image.raw
Convert synthetic input:
ffmpeg -y -video_size 768x576 -pix_fmt rgb24 -i test_image.raw -pix_fmt yuvj444p test_image.jpeg
I found the solution:
Apparently the raw image format is "planar" RGB:
RRRRR
RRRRR
RRRRR
GGGGG
GGGGG
GGGGG
BBBBB
BBBBB
BBBBB
Converting it to jpeg (using FFmpeg
) is a complicated problem:
ffmpeg -y -video_size 768x576 -pix_fmt gbrp -i m-001-1.raw -filter_complex "extractplanes=g+b+r[g][b][r],[r][g][b]mergeplanes=0x001020:gbrp[v]" -map "[v]" m-001-1.jpeg
FFmpeg
has no support for raw "planar" RGB format.
The only "planar" that is close to RGB is GBR (green plane is first).
I used extractplanes
and mergeplanes
for reordering the color channels.
ImageMagick
has a much more simple solution:
magick.exe -depth 8 -interlace plane -size 768x576 rgb:image.raw image.jpeg
Example:
Since stackoverflow
not allowing upload of raw
files, I uploaded a png
image in grayscale
format that simulates the "planar" RGB:
For testing the solution use the following steps:
D5IUp.png
). png
to raw
as "planar" RGB" (.y
extension):ffmpeg -y -i D5IUp.png -c:v rawvideo -pix_fmt gray D5IUp.y
raw
to jpeg
:ffmpeg -y -video_size 128x96 -pix_fmt gbrp -i D5IUp.y -filter_complex "extractplanes=g+b+r[g][b][r],[r][g][b]mergeplanes=0x001020:gbrp[v]" -map "[v]" D5IUp.jpeg
Example for batch conversion using ImageMagick
:
for %%f in (*.raw) do (magick.exe -depth 8 -interlace plane -size 768x576 rgb:"%%f" "%%~nf.jpeg")