1

I do photogrammetry with Nikon cameras. However, I've noticed that when I save my photos in grayscale in JPG format, I get images with three channels and slightly different values on each JPG with 3 channels. So, I've decided to save my photos in RAW format (NEF for Nikon).

I'm looking for software, on Windows, that I could use in command line and that would allow me to read my 14-bit NEF images and convert them to grayscale in 8-bit TIF format.

I found a function with ufraw that does exactly what I want but it's very slow (7 seconds for a 24Mpx image):

ufraw-batch.exe "XXX.NEF" --grayscale=mixer --grayscale-mixer=0.299,0.587,0.114 --out-type=tif --out-depth=8 --output="XXX.tif"

I tried with ImageMagick : magick.exe "XXX.NEF" -colorspace gray -depth 8 "XXX.tif"

However, I get overexposed images (white saturates at 255), I feel like it apply a bad color parameter but I can't apply custom parameters.

Finally, I tried with darktable-cli but I can't convert to grayscale.

Do you have any ideas or tips?

8
  • I'm puzzled by your comment about JPG save as greyscale having three channels with slightly different numbers in each. A true JPG greyscale format should be single luminance Y channel and copied to each of RGB for display purposes. Some commercial photo print machines cannot handle them at all. A 3 channel greyscale JPG image where there is YCrCb (standard JPEG encoding) should have everything in Y and both of the Cr,Cb set to identically zero. There should be no channel differences at all. Can you post small sample images that demonstrate these symptoms? Commented Feb 28 at 9:59
  • Thanks for your answer, I just added a small image in my post. Commented Feb 28 at 10:46
  • With Imagemagick 6.9.13-7, I do see a slight difference in statistics. That is indeed very strange. How did you save the JPG? Did you use Imagemagick for that or is this JPG straight from your camera? What is your Imagemagick version. Imagemagick 6 will show 3 channels for a grayscale image, but they should all be the same. Is it possible that this is a malfunction in your camera.
    – fmw42
    Commented Feb 28 at 16:59
  • Your JPG image is truecolor not grayscale. Even EXIFTOOL says it has 3 color components. Why do you believe it should be grayscale? Check your camera settings
    – fmw42
    Commented Feb 28 at 17:19
  • The JPG come from the camera. I just applied a Color Profil "Monochrom" in my camera settings, but this transformation seems to be wrong. Commented Feb 29 at 7:45

1 Answer 1

0

There is a 6000x4000 JPEG embedded in your NEF file which you can extract instantaneously with exiftool as follows:

exiftool -b -JpgFromRaw 043_0010.NEF  > preview.jpg

Maybe that is useful to you? You can convert it to TIFF if you want to with ImageMagick:

exiftool -b -JpgFromRaw 043_0010.NEF | magick - -compress LZW preview.tif

Extra info... by the way, you can find all the information buried in your NEF file using:

exiftool -s 043_0010.NEF 

Then I just looked for the name of the biggest binary lump to extract with -b option on the basis that that is probably the best quality. Doubtless more scientific approaches exist😉

5
  • You might want to add -gamma 2 or similar into the ImageMagick command to get something visible, btw. Commented Mar 1 at 12:13
  • Thank you for your answer, your second command do what I want, but I would prefer to keep the image uncompressed during the process to keep the maximum quality. Is it possible to do that without the jpeg and pass directly from the raw to the tiff ? Commented Mar 1 at 15:46
  • No, it's already a compressed JPEG inside the NEF file so you'd really need to process the raw data if you want to retain the full quality. However, you do still have 6000x4000 resolution, and remember a fairly considerable part of the quality loss in JPEG is caused by chroma subsampling and given that you are only using monochrome images anyway, the colour loss in JPEG may not be a big issue for you. I would suggest you try and do your photogrammetry with the image exiftool gives you and see if it is sufficient. Keep the NEF file too though😉 Commented Mar 1 at 15:59
  • You could also experiment and see if changing the settings on your camera alters the quality of the JPEG you get from the NEF. You can use magick identify -verbose EXIFTOOLEXTRACTEDIMAGE.JPG to see the parameters your camera used to make the JPEG - for example, the quality is currently 76 and there is chroma subsampling. Commented Mar 1 at 16:21
  • 1
    Finally it's better to save color JPEG on my camera with high quality and then to convert in grayscale tiff. Commented Mar 5 at 8:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.