Specifically, with a given image I’m trying to decrease the RGB values for each pixel by 100.
For example, if a pixel has R: 232, G: 40, B: 120 then I want the new RGB values to be R: 132, G: 0, B: 20.
I have tried this solution that I found on the ImageMagick forums:
convert input.jpg -channel R -evaluate subtract 25700 \
-channel G -evaluate subtract 25700 \
-channel B -evaluate subtract 25700 output.jpg
Edit: the reason I use 25700 is because apparently you need to multiply the rgb value by 257. 100 * 257 = 25700.
While it appears to work at first (clearly darkening the image), it seems that certain pixels will not change and for what I’m doing it’s vital that they do (I’m running a trim on the resulting image, trying to trim away the border with pixel values of 0).
An common problem is that I’ll end up with a pixel that has a RGB values of 3, 0, 0, but I’ll want that pixel to have values of 0 for RGB and increase the constant I subtract by – but it doesn’t seem to work.
Any ideas? Thanks!
Honestly, I don’t really understand what the value
25700in your commandline should achieve.However, I suggest a different commandline to you, using the more powerful
-fxoperator. A bit more complicated looking, but hopefully more intuitively to understand…But first, I’m looking at your description and see you want to subtract a fixed number of
120from each of the current R, G, and B color values. So this is a gray pixel color… and as you can look up in ImageMagick’s color built-in color list, its name isgray47:This leads me to the following command:
This way or writing the command will probably open your eyes to some easily derived modifications should you need those in future…
To have an immediate preview window of the result popping up (without writing it to a file) you can also use
-show:as output, like this:Update
If you want to check for the real differences of each pixel, you can make ImageMagick print out the color value for each pixel:
The format of the .txt file is pretty easy to understand, once you know that the first columns give the Pixel zero-based coordinates:
123,456:means: 124th (!) column, 457th () row.Now you can compare the two .txt files to your heart’s content even in an automated, scripted version, without a need to resort to Gimp. 🙂
You could even use
input.txtand apply a Perl-, Ruby-, Python- or Shellscript onto each of the pixel values to distract your120value from each channel, save it as output2.txt and then convert it back to JPEG:Then look for pixel differences between the two output images:
An all-white plane will mean ‘no differences’ , any red pixels will hint to some sort of delta.
Now if that answer doesn’t earn me an upvote, I don’t know which would… 🙂