Page 1 of 2

8-bit raw little-endian to color PNG

Posted: 2013-08-06T14:45:03-07:00
by acoustic7
Hello all,

Right now I have a bunch of .bsv files that contain color image data. Right now, to get the end result of color pngs, I am importing each .bsv as a raw 8-bit in imagej with little-endian byte order. This creates 40 8-bit grayscale images which I can save as .tif. Then I've been using imagemagick and mogrify to change the format of the .tif's to .pgm. Then I give all of those .pgm to this Debayer program:
http://www.fastcompression.com/products ... ebayer.htm
using this loop:

Code: Select all

for %a in (0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39) do DebayerGPU.exe -demosaic DFPD_R -CPU -pattern GRBG -i single%a.pgm -o single%a.ppm
then I finally use imagemagick and mogrify to change the outputted .ppm's to png.

Is there a way to do all of this with just imagemagick? Can imagemagick import raw data? And does imagemagick have a debayering tool?

Thanks for the help!

Re: 8-bit raw little-endian to color PNG

Posted: 2013-08-06T15:00:46-07:00
by GreenKoopa
ImageMagick can import raw. IM delegates Bayer processing to dcraw. Alternatively dcraw can be used directly as a first step, and IM used for later steps.
http://www.imagemagick.org/Usage/formats/#crw

Re: 8-bit raw little-endian to color PNG

Posted: 2013-08-06T15:38:12-07:00
by fmw42
I do not see Bayer raw format explicitly in the list of IM formats at http://www.imagemagick.org/script/formats.php. But IM uses dcraw to open raw formats. So if dcraw can handle it, then IM can do it, I would expect. See http://chdk.setepontos.com/index.php?topic=4963.0

Re: 8-bit raw little-endian to color PNG

Posted: 2013-08-11T13:36:18-07:00
by acoustic7
That's great, how do I actually download and install this dcraw add-on?

Re: 8-bit raw little-endian to color PNG

Posted: 2013-08-11T13:38:12-07:00
by Bonzo
dcraw should be installed with Imagemagick; I can work on Canon RAW files in Imagemagick without any additional programs.

Why not try a simple convert and see what happens:

Code: Select all

convert input.raw output.png

Re: 8-bit raw little-endian to color PNG

Posted: 2013-08-11T15:08:33-07:00
by acoustic7
Ok, I installed dcraw successfully. But the problem is that the file isn't of type .raw. It's of type .bsv.

Re: 8-bit raw little-endian to color PNG

Posted: 2013-08-11T16:24:39-07:00
by snibgo
What is a ".bsv" file? Dcraw is for converting camera raw files, which yours doesn't seem to be.

Is bsv documented somewhere? Is there a header? How many channels? How many bytes per channel? Compression?

Re: 8-bit raw little-endian to color PNG

Posted: 2013-08-12T07:55:31-07:00
by acoustic7
yes, there is a header file, and the reason I suspect that dcraw might be able to handle it is because I can open it in imagej with Import->raw.
The header file is quite large, and has a ton of metrics, but I'm not sure what most of them mean. Imagej asks for Image Type: (8-bit), Width: (4000 pixels), Height: (2672 pixels), Offset to first image: (0 bytes), Number of images: (40), Gap between images: (0 bytes), and then I check the box that says "little-endian byte order". But the header has values for tons of other things.

Re: 8-bit raw little-endian to color PNG

Posted: 2013-08-12T08:37:06-07:00
by snibgo
Hmm. According to Wikipedia, bsv is an old file format for saving/loading images from/to display adapter memory.

Where did your bsv files come from? If I were you, I'd convert them all to a more modern format (such as png) while you still can.

Re: 8-bit raw little-endian to color PNG

Posted: 2013-08-12T09:31:14-07:00
by acoustic7
I'm trying to convert them to png. . . that is the entire point of this original post. . .

Re: 8-bit raw little-endian to color PNG

Posted: 2013-08-12T09:57:51-07:00
by snibgo
And Imagej successfully converts them? Good. What problem are you tying to solve with IM?

IM can read binary files that contain uncompressed pixel data. But it can't skip over a header and trailer; you would need to do that outside IM.

IM contains no explicit debayer (demosaicing) algorithms, although IM operators can be used as building blocks for interpolation demosaicing.

Re: 8-bit raw little-endian to color PNG

Posted: 2013-08-12T11:43:43-07:00
by acoustic7
The reason I'm trying to use IM is because I'm attempting to create a .bat file. I have a ton of these .bsv files, and clicking and importing and saving each one with imagej is tedious. If I can figure out how to do it in imagemagick, then I can write a few lines of command line. I don't need to do the debayering with imagemagick, I have a command-line gpu program that will debayer them.

Re: 8-bit raw little-endian to color PNG

Posted: 2013-08-12T13:38:04-07:00
by glennrp
snibgo wrote: IM can read binary files that contain uncompressed pixel data. But it can't skip over a header and trailer; you would need to do that outside IM.
Read up on the "-size" option:
  • use -size with an offset to skip any header information in the image
That won't work, of course, if you need to actually interpret the header and use the
information from it to decode the image.

Re: 8-bit raw little-endian to color PNG

Posted: 2013-08-12T13:50:47-07:00
by snibgo
Thanks, -size can skip over a header. But not a trailer?

Re: 8-bit raw little-endian to color PNG

Posted: 2013-08-12T14:05:00-07:00
by glennrp
snibgo wrote:Thanks, -size can skip over a header. But not a trailer?
-size also tells the app how much to read. When it has all the pixels it stops.