Greyscale shift or Interpolation
Greyscale shift or Interpolation
Hi Team,
Can anyone have any idea how we can get the image lowest and highest pixel in an image. And also what I need to do is that we need to get the images lighter value and darker values and also need to adjust the low as well as high values to user defined.
Like we have an image with a color range of 0-235 and we need to narrowed that range to 50-200. It would take our darkest color (0) and bump it to 50, and proportionally adjust the balance of the colors up, with the consideration that the colors from 255 were also being adjusted to 200.
How can I do this by using ImageMagick commands? I am using OS as CentOS and my ImageMagick version is 7.0.8.
Please provide your suggestions.
Can anyone have any idea how we can get the image lowest and highest pixel in an image. And also what I need to do is that we need to get the images lighter value and darker values and also need to adjust the low as well as high values to user defined.
Like we have an image with a color range of 0-235 and we need to narrowed that range to 50-200. It would take our darkest color (0) and bump it to 50, and proportionally adjust the balance of the colors up, with the consideration that the colors from 255 were also being adjusted to 200.
How can I do this by using ImageMagick commands? I am using OS as CentOS and my ImageMagick version is 7.0.8.
Please provide your suggestions.
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Greyscale shift or Interpolation
You can get the minimum and maximum pixel values, on a scale from 0.0 to 1.0, like this (bash syntax):
If you prefer a scale from 0.0 to 255.0, you can multiply:
My input already spans the full range. If it didn't, I could "-auto-level" first.
To reduce the range, use "+level". See http://www.imagemagick.org/script/comma ... .php#level . I generally use this with percentages, like this:
It can be used with "%[fx:]" expressions, for example:
Code: Select all
$ magick toes.png -format "%[fx:minima]\n%[fx:maxima]\n" info:
0
1
Code: Select all
$ magick toes.png -format "%[fx:minima*255]\n%[fx:maxima*255]\n" info:
0
255
To reduce the range, use "+level". See http://www.imagemagick.org/script/comma ... .php#level . I generally use this with percentages, like this:
Code: Select all
$ magick toes.png +level 25,75% out.png
Code: Select all
$ magick toes.png +level "%[fx:50/255*100],%[fx:200/255*100]%" -format "%[fx:minima*255]\n%[fx:maxima*255]\n" info:
49.9999
200
snibgo's IM pages: im.snibgo.com
Re: Greyscale shift or Interpolation
Here what we are trying to achieve is to convert all the pixels from an image below color value 50 to 50 and the pixel with color value above 200 to 200. For example, is a pixel has color value 30, it should be automatically converted to 50. Similarly, if a pixel has color value 250, it should be converted to 200.
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Greyscale shift or Interpolation
I showed you one method to do that. It also adjusts values that were between 50 and 200.
Perhaps you want those values unchanged. In that case, "-evaluate Max 20%" will change any values that were less than 20% to be 20%, without changing other values.
Similarly "-evaluate Min 80%" will change values that are above 80% to be 80%.
As above, you can use %[fx:] expressions.
Perhaps you want those values unchanged. In that case, "-evaluate Max 20%" will change any values that were less than 20% to be 20%, without changing other values.
Similarly "-evaluate Min 80%" will change values that are above 80% to be 80%.
As above, you can use %[fx:] expressions.
snibgo's IM pages: im.snibgo.com
Re: Greyscale shift or Interpolation
Hello Snibgo,
Thank you for your reply.
Can you please provide any sample command of ImageMagick for the pixel range need to change which is less then 20 & greater then 200?
I need the IM command and will check at my end with the different range of pixels.
Thanks in advanced.
Thank you for your reply.
Can you please provide any sample command of ImageMagick for the pixel range need to change which is less then 20 & greater then 200?
I need the IM command and will check at my end with the different range of pixels.
Thanks in advanced.
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Greyscale shift or Interpolation
Code: Select all
magick in.png -evaluate Max %[fx:20/255*100]% -evaluate Min %[fx:200/255*100]% out.png
snibgo's IM pages: im.snibgo.com
Re: Greyscale shift or Interpolation
Thanks Snibgo.
One point I need to confirm in above sample command.
The value 20 and 200 are the pixel color values that will be matching in an image to replace with less & greater values respectively.
Also I did checked with the PNG transparent image and found that the effect is also applying on transparent area of an image. Please see the source and output image and below is the command which I have used.
Command -
magick finalOP-20190219143847.png -evaluate Max %[fx:50/255*100]% -evaluate Min %[fx:180/255*100]% out25_1.png
Source Image -
https://www.dropbox.com/s/j98tcf3ifd5sp ... 7.png?dl=0
Output Image -
https://www.dropbox.com/s/na8l66yremg90 ... 1.png?dl=0
Please review at your end and provide your feedback.
One point I need to confirm in above sample command.
The value 20 and 200 are the pixel color values that will be matching in an image to replace with less & greater values respectively.
Also I did checked with the PNG transparent image and found that the effect is also applying on transparent area of an image. Please see the source and output image and below is the command which I have used.
Command -
magick finalOP-20190219143847.png -evaluate Max %[fx:50/255*100]% -evaluate Min %[fx:180/255*100]% out25_1.png
Source Image -
https://www.dropbox.com/s/j98tcf3ifd5sp ... 7.png?dl=0
Output Image -
https://www.dropbox.com/s/na8l66yremg90 ... 1.png?dl=0
Please review at your end and provide your feedback.
Re: Greyscale shift or Interpolation
Hello Everyone,
Can I have any further updates for my above query on transparent image? Please provide your valuable feedback ASAP.
Thanks in advanced
Can I have any further updates for my above query on transparent image? Please provide your valuable feedback ASAP.
Thanks in advanced
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Greyscale shift or Interpolation
You can restrict the operation to just the RGB channels:
I get a warning about your input file:
Code: Select all
magick finalOP-20190219143847.png -channel RGB -evaluate Max %[fx:50/255*100]% -evaluate Min %[fx:180/255*100]% +channel out25_1.png
Code: Select all
magick: invalid profile length `finalOP-20190219143847.png' @ warning/png.c/MagickPNGWarningHandler/1744.
snibgo's IM pages: im.snibgo.com