Gamma correction for JPG file

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?".
Post Reply
splee
Posts: 15
Joined: 2011-07-08T22:21:01-07:00
Authentication code: 8675308

Gamma correction for JPG file

Post by splee »

I understand that JPG file (sRGB) are corrected for gamma (2.2 if I am not wrong).
How do I "de-gamma" it? i.e. remove the gamma correction, using command line option?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Gamma correction for JPG file

Post by fmw42 »

try converting it to a linear color colorspace, RGB or use -gamma 1/2.2 = 0.454545

convert image.jpg -colorspace RGB newimage.jpg

convert image.jpg -gamma 0.454545 newimage.jpg
splee
Posts: 15
Joined: 2011-07-08T22:21:01-07:00
Authentication code: 8675308

Re: Gamma correction for JPG file

Post by splee »

I tried "convert image.jpg -gamma 0.454545 newimage.jpg" but it gave me the following error:
"Insufficient memory (case 4) newimage.jpg @ error/jpeg.c/JPEGErrorHandler/296"

Then I tried this "convert -limit memory 1 -limit map 1 image.jpg -gamma 0.454545 newimage.jpg" but it gave me the following error:
"unable to extend cache 'image.jpg': No space left on device @ error/cache.c/OpenPixelCache/4139"
"Application transferred too few scanlines image.jpg @ warning/jpeg.c/JPEGErrorHandler/293"
...


What else can I do?

I am using WinXP command line option. The file size is 50MB
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Gamma correction for JPG file

Post by anthony »

Sounds to me like your computer has no disk space available!
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
splee
Posts: 15
Joined: 2011-07-08T22:21:01-07:00
Authentication code: 8675308

Re: Gamma correction for JPG file

Post by splee »

oh yes "convert -limit memory 1 -limit map 1 image.jpg -gamma 0.454545 newimage.jpg" works after I freed some harddisk space.

However "convert image.jpg -gamma 0.454545 newimage.jpg" still fails. Must I use the "-limit memory 1 -limit map 1" all the time? What is this option doing actually?
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Gamma correction for JPG file

Post by anthony »

Forcing the use of temporary disk for image data cache, rather than memory, though that switch should be reasonably automatic.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
splee
Posts: 15
Joined: 2011-07-08T22:21:01-07:00
Authentication code: 8675308

Re: Gamma correction for JPG file

Post by splee »

Hi Anthony,
I want the so called "raw" image pixel, ie. with the gamma effect removed.
Are you sure it is "-gamma 0.454545", not "-gamma 2.2"?
I am confused.
Could you please help?
Thanks...
henrywho
Posts: 188
Joined: 2011-08-17T06:46:40-07:00
Authentication code: 8675308

Re: Gamma correction for JPG file

Post by henrywho »

Why not "-colorspace RGB". It converts your image to linear RGB for further operations.

sRGB is very similar to gamma 2.2, but not exactly the same. Not sure about AdobeRGB (some DC produces AdobeRGB instead of sRGB).
Post Reply