Hie.
I'm trying to color balance a photo. I've learned from fred's excellent script (whitebalance) that I can do it if I specify the % or a pixel location of a white pixel.
I got that part working without a glitch but now I want to make it more robust and locate the position of the white pixel automagically without me telling him where it is.
I went through the posts and help files but couldn't solve it. I'm pretty sure i need to use the -format or -fx features but I didn't find the correct syntax.
I've managed to replace the white/close to white colors but I only need the coordinates of a "white" pixel to feed them to the next function.
Any help would be very much appreciated.
Shahar Zrihen
Finding the first white pixel
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Finding the first white pixel
Exactly white or close to white. If close to white, how close? What happens if there is no exactly white pixel?
This will locate the first occurrence of a pure white pixel in the gradient image.
convert -size 128x128 gradient: -rotate 90 grad_tmp.png
compare -metric rmse -subimage-search -dissimilarity-threshold 1 grad_tmp.png \( -size 1x1 xc:white \) null:
0 (0) @ 127,0
So it as x=127 and y=0 ( top right of the gradient as it should be )
see
http://www.imagemagick.org/script/compare.php
http://www.imagemagick.org/Usage/compare/
Alternately,
convert grad_tmp.png txt:- | grep "white" | head -n 1
127,0: (65535,65535,65535) #FFFFFFFFFFFF white
see
http://www.imagemagick.org/Usage/files/#txt
This will locate the first occurrence of a pure white pixel in the gradient image.
convert -size 128x128 gradient: -rotate 90 grad_tmp.png
compare -metric rmse -subimage-search -dissimilarity-threshold 1 grad_tmp.png \( -size 1x1 xc:white \) null:
0 (0) @ 127,0
So it as x=127 and y=0 ( top right of the gradient as it should be )
see
http://www.imagemagick.org/script/compare.php
http://www.imagemagick.org/Usage/compare/
Alternately,
convert grad_tmp.png txt:- | grep "white" | head -n 1
127,0: (65535,65535,65535) #FFFFFFFFFFFF white
see
http://www.imagemagick.org/Usage/files/#txt
Re: Finding the first white pixel
Thanks for the quick reply.
I'm looking for the "closest to white" solution and if there's no white pixels I would love to get an error message.
I thought about doing it with a threshold number.
My idea is to use the whitebalance script with a script that would find the white marker used in the image instead of supplying it's X,Y coordinates or having to put the marker at the same spot every time.
You script will not help me since I need "closest to white". Sorry if I wasn't clear the first time.
Shahar
I'm looking for the "closest to white" solution and if there's no white pixels I would love to get an error message.
I thought about doing it with a threshold number.
My idea is to use the whitebalance script with a script that would find the white marker used in the image instead of supplying it's X,Y coordinates or having to put the marker at the same spot every time.
You script will not help me since I need "closest to white". Sorry if I wasn't clear the first time.
Shahar
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Finding the first white pixel
add -fuzz to the compare
compare -metric rmse -fuzz XX% -subimage-search -dissimilarity-threshold 1 yourimage \( -size 1x1 xc:white \) null:
That will locate near white values within the fuzz % difference.
Alternately, and again simpler, you can auto-level the image to stretch near white to white and use the other method
convert yourimager -auto-level txt:- | grep "white" | head -n 1
This will report the location of the closest white value as it has now become white
compare -metric rmse -fuzz XX% -subimage-search -dissimilarity-threshold 1 yourimage \( -size 1x1 xc:white \) null:
That will locate near white values within the fuzz % difference.
Alternately, and again simpler, you can auto-level the image to stretch near white to white and use the other method
convert yourimager -auto-level txt:- | grep "white" | head -n 1
This will report the location of the closest white value as it has now become white
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: Finding the first white pixel
I suggest converting the image to grayscale, and output 16 bit depth values to a txt: image
You can then sort, or simply go though the output list and look for the brightest pixel in the whole image.
You can also use 'max' function on the grayscale image to get the brightness level of the brigthest pixel.
I'll leave it to Fred (previous responder to get you the details.
You can then sort, or simply go though the output list and look for the brightest pixel in the whole image.
You can also use 'max' function on the grayscale image to get the brightness level of the brigthest pixel.
I'll leave it to Fred (previous responder to get you the details.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Finding the first white pixel
I am not sure you can get near-white with -fuzz that way? Also you still don't have the coordinates for the "max" value.anthony wrote:
You can also use 'max' function on the grayscale image to get the brightness level of the brigthest pixel.