3

I got a RAW image file (from a camera sensor module) which does not contain any metadata inside, but I know the metadata from other source, i.e., its width*height, and the depth (8-bit grey). How can I tell imagemagick utilities (convert, e.g.) to convert it to other formats?

Btw, I can open it using Photoshop (by telling it the metadata in a popup dialog), but Photoshop is not conveninent for my task at hand.

Thanks,

/bruin

bruin
  • 979
  • 1
  • 10
  • 30

2 Answers2

9

In ImageMagick you use the -size and -depth arguments with the qualifier of GRAY or RGB depending upon if your file is grayscale or color. So

convert -size WIDTHxHEIGHT -depth 8 GRAY:inputname.suffix outputname.newsuffix

newsuffix might be gif, tif, png, jpg, etc. suffix may or may not exist, but could be bin or something else.

But you will need to have dcraw or ufraw depending upon your OS compiled on your system, since ImageMagick uses those to do the work. You could also use those standalone without ImageMagick

fmw42
  • 46,825
  • 10
  • 62
  • 80
  • Thanks for your help, it works for me! I am using ImageMagick on CentOS 7. "convert" works for me even "dcraw" package is not installed on my system. Also, yum seems don't know the pkg "ufraw". Thanks again! – bruin Jun 01 '17 at 05:33
  • 1
    Fred - the `dcraw/ufraw` package is only needed if you have an image like `xxx.CR2` (Canon), or `xxx.NEF` (Nikon), or `xxx.raf` (Fuji), or `xxx.mrw` (Konica/Minolta) that needs demosaicing, gamma correction, noise reduction etc. If you just have a simple load of concatenated RGB/grey values, then you won't need the `dcraw` and `ufraw` packages. – Mark Setchell Jun 01 '17 at 09:26
  • 1
    Thanks for the correction, Mark. I don't usually use raw images and a photographer like you would know more about this than I. But what you say does make sense, now that I think about it. – fmw42 Jun 01 '17 at 16:33
0

I'm also working with raw images (as in binary files containing pixel values with no header) and fmw42's answer helped me out.

I found it tricky to figure out how to downsample the bit depth. In my case, the raw files contained 10 bits per pixel, unpacked (that is, 16 bits per pixel but only 10 bits are significant). To map that correctly to an 8 bpp output, do:

convert -size WIDTHxHEIGHT -depth 16 GRAY:inputname.suffix -level 0,1023,1.0 -depth 8 outputname.newsuffix

Without -level, all 16 bits are downsampled to 8, resulting (in my case) in what was effectively a 2 bit image stored at 8 bits per pixel.

darda
  • 3,597
  • 6
  • 36
  • 49