fix simple debayer with imagemagick
Closed, ResolvedPublic

Description

The method to cerate a simple debayer image from a raw12:

cat test.raw12 | convert \( -size 4096x3072 -depth 12 gray:- \) \( -clone 0 -crop -1-1 \) \( -clone 0 -crop -1+0 \) \( -clone 0 -crop +0-1 \) -sample 2048x1536 \( -clone 2,3 -average \) -delete 2,3 -swap 0,1 +swap -combine test_color.png

doesn't work anymore with the newer imagemagick versions

Needs fixing.

Ashok added a subscriber: Ashok.EditedMar 4 2020, 5:05 PM

I have used the latest stable release of imageMagick (which is ImageMagick 7.0.9-27) to run

cat index.raw12 | convert \( -size 4096x3072 -depth 12 gray:- \) \( -clone 0 -crop -1-1 \) \( -clone 0 -crop -1+0 \) \( -clone 0 -crop +0-1 \) -sample 2048x1536 \( -clone 2,3 -average \) -delete 2,3 -swap 0,1 +swap -combine test_color.png

and according to me it gave the desired output.

NOTE: Since no test file was given I used the one which I already had. The test file and the result are attached with this comment.

Will try the command itself soon but from just looking at your post: the output file is monochrome but should be color...

This comment was removed by sebastian.
Bertl added a subscriber: Bertl.Mar 9 2020, 6:18 PM

It seems that the sample point was moved in recent versions so now the samples average the four channels into one gray value.

Adding -define sample:offset=0 should fix the issue.

Best,
Herbert

Ashok added a comment.Mar 11 2020, 4:50 PM

Thanks Bertl for the direction.

In ImageMagick 7 we have to explicitly put -gravity SouthEast and -define sample:offset=0 to get desire simple debayer image from a raw12 as default sample point has been moved after ImageMagick 6 :.

cat test.raw12 | convert -define sample:offset=0 -gravity SouthEast \( -define sample:offset=0 -size 4096x3072 -depth 12 gray:- \) \( -clone 0 -crop -1-1 \) \( -clone 0 -crop -1+0 \) \( -clone 0 -crop +0-1 \) -sample 2048x1536 \( -clone 2,3 -average \) -delete 2,3 -swap 0,1 +swap -combine test_color.png;

Best Regards,
Ashok

Works, many thanks!

Bertl added a comment.EditedMar 11 2020, 6:59 PM

This should avoid the sample point setting:

convert \( -size 4096x3072 -depth 12 gray:portrait.raw12 \) \( -clone 0 -roll -1-1 \) \( -clone 0 -roll -1+0 \) \( -clone 0 -roll +0-1 \) -sample 2048x1536 \( -clone 2,3 -average \) -delete 2,3 +swap -combine portrait.png

and

convert \( -size 4096x3072 -depth 12 gray:image00002.raw12 \) \( -clone 0 -roll -1-1 \) \( -clone 0 -roll -1+0 \) \( -clone 0 -roll +0-1 \) -sample 2048x1536 \( -clone 2,3 -average \) -delete 2,3 -swap 0,2 -combine image00002.png

Tested on ImageMagick v7 but should work for v6 as well.
Adjust -depth12 to -depth16 for raw16 sources.

Hope this helps,
Herbert

sebastian closed this task as Resolved.Mar 11 2020, 7:32 PM
sebastian claimed this task.

Perfect, tested and verified! Thanks!
Will update wiki now.

Ashok added a comment.Mar 11 2020, 7:36 PM
This comment was removed by Ashok.

hey Sebastian,
I am not getting desired output by running 2nd command. Is there some typo ?
Because on switching the last two images in the sequence. i.e -swap 1,2 gives correct output.

cat test.raw12 | convert \( -size 4096x3072 -depth 12 gray:- \) \( -clone 0 -roll -1-1 \) \( -clone 0 -roll -1+0 \) \( -clone 0 -roll +0-1 \) -sample 2048x1536 \( -clone 2,3 -average \) -delete 2,3 -swap 1,2 -combine test_color.png

What output do you get?

The first command is for raw12 files captured with swapped even/odd lines, the second command is for non swapped even/odd lines. So using the two commands on the same image will indeed create one output with wrong colors.

Ashok added a comment.Mar 12 2020, 3:03 PM

Ohh sorry my bad, Didn't considered 2nd condition.
Thank you for the explanation.

Regards,
Ashok