Image Magik is having a hard time with 14 Bits Per Sample

Questions and postings pertaining to the development of ImageMagick, feature enhancements, and ImageMagick internals. ImageMagick source code and algorithms are discussed here. Usage questions which are too arcane for the normal user list should also be posted here.
ksampan
Posts: 16
Joined: 2018-01-10T21:51:21-07:00
Authentication code: 1152

Image Magik is having a hard time with 14 Bits Per Sample

Post by ksampan »

Hi team,

IM version : 7.0.3-Q16
Camera Model : Nikon D850

I have a raw image .nef file which I am trying to convert in to jpg file of particular resolution but after conversion, the color changes from the actual image color.

Command :
magick.exe NEF:C:\850_0087.NEF -intent relative -colorspace sRGB -strip -auto-orient C:\test\a.jpg

Observation:
-I have tested NEF image with camera model (NIKON D1X). It is working fine.
-The difference observed is *Bits Per Sample* is different for the images that were captured from both cameras.

Bits Per Sample :
Nikon D850 - 14
NIKON D1X - 12

Please help me out.

Thanks
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Image Magik is having a hard time with 14 Bits Per Sample

Post by snibgo »

I don't understand what problem you have. Where do you get the "*Bits Per Sample*" from?

The D850 records 14 bits/pixel. The D1X records 12 bits/pixel. (Both are linear in the Raw, of course.) So any software that says so is correct.

JPEG is only 8 bits/channel/pixel.
snibgo's IM pages: im.snibgo.com
ksampan
Posts: 16
Joined: 2018-01-10T21:51:21-07:00
Authentication code: 1152

Re: Image Magik is having a hard time with 14 Bits Per Sample

Post by ksampan »

Hi snibgo,
Thanks for the reply,

I am trying convert NEF file to jpg format. The color is getting changed after image coversion.The image is getting darker.Please find the difference in the url provided (https://drive.google.com/file/d/1p3GChB ... sp=sharing).Original image is on Right side.
For your information Bits Per Sample is metadata extracted for an image using exiftool.

Thanks
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Image Magik is having a hard time with 14 Bits Per Sample

Post by Bonzo »

NEF seems to be a problem format as it comes up now and again. I would suggest searching the forum as there are other posts. In fact one users image was to red!
ksampan
Posts: 16
Joined: 2018-01-10T21:51:21-07:00
Authentication code: 1152

Re: Image Magik is having a hard time with 14 Bits Per Sample

Post by ksampan »

Thanks for the reply,

I have gone through many of the posts and tried. But couldn't find a solution for that.please help me out.
There was a simliar issue https://www.imagemagick.org/discourse-s ... hp?t=29340 . But that solution couldnt solve my problem.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Image Magik is having a hard time with 14 Bits Per Sample

Post by snibgo »

NEF isn't a problem format. It is a popular format that shows a common problem in IM, a missing "-w". See below.

What delegate is reading the raw file? "-verbose" will tell you, eg:

Code: Select all

f:\web\im>%IMG7%magick -verbose AGA_3443.nef x.tiff
dcraw.exe -6 -w -W -O "C:/Users/Alan/AppData/Local/Temp/magick-55926vsQFeNX8EXE.ppm" "C:/Users/Alan/AppData/Local/Temp/magick-5592T1I4iY-6NKQS"
C:/Users/Alan/AppData/Local/Temp/magick-55926vsQFeNX8EXE.ppm PPM 4924x7378 4924x7378+0+0 16-bit sRGB 218MB 0.219u 0:00.233
AGA_3443.nef=>C:/Users/Alan/AppData/Local/Temp/magick-55926vsQFeNX8EXE.ppm NEF 4924x7378 4924x7378+0+0 16-bit sRGB 218MB 0.016u 0:00.016
AGA_3443.nef=>x.tiff NEF 4924x7378 4924x7378+0+0 16-bit sRGB 218MB 0.516u 0:03.281
The delegate used here is dcraw.exe. Your system might use ufraw-batch.exe.

Please paste here your text output from the verbose.

Notice that the dcraw command includes "-w", lower-case w. This tells dcraw to use the white-balance recorded by the camera. Some versions of IM don't include "-w".

The fix is simple: open delegates.xml in a text editor, find the dcraw line(s), and insert "-w".
snibgo's IM pages: im.snibgo.com
ksampan
Posts: 16
Joined: 2018-01-10T21:51:21-07:00
Authentication code: 1152

Re: Image Magik is having a hard time with 14 Bits Per Sample

Post by ksampan »

Hi snibgo,
Thanks for the reply,

Output text from the verbose:

Code: Select all

dcraw.exe -6 -w -W -O "C:/Users/ksampan/AppData/Local/Temp/magick-45052GSCarzgSVSaV.ppm" "C:/Users/ksampan/AppData/Local/Temp/magick-45052_nCXCn_Oc5ox"
C:/Users/ksampan/AppData/Local/Temp/magick-45052GSCarzgSVSaV.ppm PPM 8288x5520 8288x5520+0+0 16-bit sRGB 274.5MB 0.188u 0:00.189
C:\Users\ksampan\Desktop\NEF\850_0087.NEF=>C:/Users/ksampan/AppData/Local/Temp/magick-45052GSCarzgSVSaV.ppm NEF 8288x5520 8288x5520+0+0 16-bit sRGB 274.5MB 0.031u 0:00.030
C:\Users\ksampan\Desktop\NEF\850_0087.NEF=>C:\Users\ksampan\Desktop\NEF\a.jpg NEF 8288x5520 8288x5520+0+0 16-bit sRGB 9.743MB 1.031u 0:01.091
- I have inserted -w and checked, but no change is observed.
- It is easily reproducible with the command (magick.exe NEF:C:\Desktop\NEF\850_0087.NEF C:\Desktop\NEF\a2.jpg) with below image that is shared.
(https://drive.google.com/file/d/1BRfp9b ... sp=sharing)
- If you need any more details i can provide you

Thanks.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Image Magik is having a hard time with 14 Bits Per Sample

Post by snibgo »

The NEF file you uploaded (a young woman in a large crowded room) has 4284x2844 pixels. But the verbose you showed has 8288x5520. So something is wrong somewhere.

Converting that NEF with ImageMagick and dcraw, or directly with dcraw, gives virtually the same result. The result is very similar to the internal JPEGs embedded within the NEF, but those are lighter with bad clipping.
snibgo's IM pages: im.snibgo.com
ksampan
Posts: 16
Joined: 2018-01-10T21:51:21-07:00
Authentication code: 1152

Re: Image Magik is having a hard time with 14 Bits Per Sample

Post by ksampan »

Sorry that was for different image i posted it for example.
For that image below is the verbose text :

Code: Select all

dcraw.exe -6 -w -W -O "C:/Users/ksampan/AppData/Local/Temp/magick-36612Ms6DiQvxyuwj.ppm" "C:/Users/ksampan/AppData/Local/Temp/magick-366120FbfcusphJT6"
C:/Users/ksampan/AppData/Local/Temp/magick-36612Ms6DiQvxyuwj.ppm PPM 4284x2844 4284x2844+0+0 16-bit sRGB 73.1MB 0.063u 0:00.055
C:\Users\ksampan\Downloads\da.NEF=>C:/Users/ksampan/AppData/Local/Temp/magick-36612Ms6DiQvxyuwj.ppm NEF 4284x2844 4284x2844+0+0 16-bit sRGB 73.1MB 0.000u 0:00.010
C:\Users\ksampan\Downloads\da.NEF=>C:\Users\ksampan\Downloads\sam.jpg NEF 4284x2844 4284x2844+0+0 16-bit sRGB 3.32MB 0.313u 0:00.310
Thanks.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Image Magik is having a hard time with 14 Bits Per Sample

Post by snibgo »

Code: Select all

f:\web\im>%IMG7%magick -verbose da.nef -resize 600x500 x2.jpg

dcraw.exe -6 -w -W -O "C:/Users/Alan/AppData/Local/Temp/magick-904083W1XBE_DYrf.ppm" "C:/Users/Alan/AppData/Local/Temp/magick-9040Um3E8uoyNS3j"
C:/Users/Alan/AppData/Local/Temp/magick-904083W1XBE_DYrf.ppm PPM 4284x2844 4284x2844+0+0 16-bit sRGB 73.1MB 0.063u 0:00.062
da.nef=>C:/Users/Alan/AppData/Local/Temp/magick-904083W1XBE_DYrf.ppm NEF 4284x2844 4284x2844+0+0 16-bit sRGB 73.1MB 0.016u 0:00.014
da.nef=>x2.jpg NEF 4284x2844=>600x398 600x398+0+0 16-bit sRGB 72.5KB 1.328u 0:00.172
Image
What result do you get?
snibgo's IM pages: im.snibgo.com
ksampan
Posts: 16
Joined: 2018-01-10T21:51:21-07:00
Authentication code: 1152

Re: Image Magik is having a hard time with 14 Bits Per Sample

Post by ksampan »

Hi snibgo,

The image you have shared is the same one i got after image coversion. There is much difference in the color of that image with the original one.please find the screenshot in the below link.(Right side is the original NEF image)

https://drive.google.com/file/d/1j9HMnf ... sp=sharing

Thanks.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Image Magik is having a hard time with 14 Bits Per Sample

Post by snibgo »

What do you mean by "the original one"? That image looks the same as the JPEGs embedded in the NEF -- brighter than the converted raw, with heavy clipping (pixels have gone whiter than white, so they are clipped at white). I show the clipping in red:
Image
The version converted by IM has no clipping. If you want to make it lighter (without clipping), you can with a power function:

Code: Select all

magick -verbose da.nef -evaluate Pow 0.7 x2.jpg
And you can increase saturation and sharpness if you want, to make your image more like the in-camera JPEG.
snibgo's IM pages: im.snibgo.com
ksampan
Posts: 16
Joined: 2018-01-10T21:51:21-07:00
Authentication code: 1152

Re: Image Magik is having a hard time with 14 Bits Per Sample

Post by ksampan »

Hi snibgo,

My requirement is the converted image should have the same clipping as of original image.
The converted image must not be brighter or lighter than the original image.It is should be same of the original.
After using Pow function im getting lighter image but it looking far away from original.

Thanks.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Image Magik is having a hard time with 14 Bits Per Sample

Post by snibgo »

The JPEG isn't the original. The converted raw is more "original" than the JPEG. To make the JPEG, the camera took the raw data and processed it in various ways.

If you want to process the raw to make it the same as the JPEG, why not use the JPEG? What is wrong with the JPEG?

Sorry, I don't understand what you want to do.
snibgo's IM pages: im.snibgo.com
ksampan
Posts: 16
Joined: 2018-01-10T21:51:21-07:00
Authentication code: 1152

Re: Image Magik is having a hard time with 14 Bits Per Sample

Post by ksampan »

Hi snibgo,

-The issue got resolved after adding -e in
<delegate decode="dng:decode" stealth="True" command="dcraw.exe -e -6 -W -O &quot;%u.ppm&quot; &quot;%i&quot;"/>
in the delegates.xml .
-But in the delegates.xml i have added a nef delegate
<delegate decode="nef" stealth="True" mode="encode" command="dcraw.exe -e -6 -w -O "%u.ppm" "%i""/>
in delegates.xml. It is not used. Only dng:decode delegate is used instead of nef delegate.

-Is there any option to forcibly use the nef delegate instead of dng:decode delegate?
Thanks,
Post Reply