8-bit raw little-endian to color PNG

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
acoustic7
Posts: 14
Joined: 2013-08-06T14:32:05-07:00
Authentication code: 6789

8-bit raw little-endian to color PNG

Post 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!
User avatar
GreenKoopa
Posts: 457
Joined: 2010-11-04T17:24:08-07:00
Authentication code: 8675308

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

Post 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
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

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

Post 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
acoustic7
Posts: 14
Joined: 2013-08-06T14:32:05-07:00
Authentication code: 6789

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

Post by acoustic7 »

That's great, how do I actually download and install this dcraw add-on?
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

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

Post 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
acoustic7
Posts: 14
Joined: 2013-08-06T14:32:05-07:00
Authentication code: 6789

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

Post by acoustic7 »

Ok, I installed dcraw successfully. But the problem is that the file isn't of type .raw. It's of type .bsv.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

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

Post 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?
snibgo's IM pages: im.snibgo.com
acoustic7
Posts: 14
Joined: 2013-08-06T14:32:05-07:00
Authentication code: 6789

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

Post 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.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

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

Post 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.
snibgo's IM pages: im.snibgo.com
acoustic7
Posts: 14
Joined: 2013-08-06T14:32:05-07:00
Authentication code: 6789

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

Post by acoustic7 »

I'm trying to convert them to png. . . that is the entire point of this original post. . .
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

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

Post 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.
snibgo's IM pages: im.snibgo.com
acoustic7
Posts: 14
Joined: 2013-08-06T14:32:05-07:00
Authentication code: 6789

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

Post 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.
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

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

Post 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.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

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

Post by snibgo »

Thanks, -size can skip over a header. But not a trailer?
snibgo's IM pages: im.snibgo.com
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

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

Post 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.
Post Reply