Page 1 of 1

Correction of -fill

Posted: 2016-05-29T13:29:33-07:00
by VanGog
Edit: You can delete this question. I have found script which solve this problem perfectly.

I better paste the images on my blog because it is faster then upload them to tinyimg (they upload images in low quality on tinyimg.com)

http://war-thunder-gaming.blogspot.cz/2016/05/im.html

This is the original image I am working with:
https://4.bp.blogspot.com/-9ya9lGdotqA/ ... ontals.jpg

convert horizontals.jpg -fuzz 25%% -fill white +opaque #c4410b horizontals_new_1.jpg
convert horizontals.jpg -fuzz 25%% -fill white +opaque #997032 horizontals_new_2.jpg

I am trying to select the orange-brown horizontals, problem is that I am not able to do it with single command and in the second image, there is pure gray, which I do not want to include.

How to get rid of the grayscale colors from the image? I know I can use -fuzz but this is not good idea because I would like to get rid of all colors which are grayscale in the sence of #111111, #222222, #333333 etc (and the nearest colors?). I think if I use fuzz this can remove the orangebrown shades of horizontals... The shades I need to get rid of are gray-violet,graygreen, grayblue, but not graybrown or grayred

Re: Correction of -fill

Posted: 2016-05-29T13:59:15-07:00
by snibgo
Your input horizontals.jpg is very blurred. For example, the dark horizontal line near the centre has picked up colour from the adjacent green and brown pixels. Do you have a better input?

We can easily make a mask of low saturation. For example:

Code: Select all

convert horizontals.jpg -colorspace HCL -channel G -separate +channel -threshold 10% g.png
Here, all output pixels are black where the input pixels were within 10% of zero saturation (eg where the input was black, mid-gray or white). Where the input was coloured, the output is white.

The percentage threshold can be varied. Bu there is no ideal value because many of the input "black" or "gray" colours are not really black or gray.

Re: Correction of -fill

Posted: 2016-05-29T14:49:23-07:00
by VanGog
I do not have better input data.

I can send you the script which I found.

I updated this post after correction of values and now it works perfectly.
I have added two samples (3 third sample is duplicate of the 1st one). As a hue I used the values directly from Photoshop in degrees.


Using batch file:

Code: Select all

Rem THIS ENABLES YOU TO SEARCH FOR 3 RANGES OF COLORS
Rem IN HSV (HSB) FORMAT 

REM Use Raw RGB values from Adobe Photoshop Color Picker:
REM Orange-Brown-Red tones
SET minH1=3
SET maxH1=39
SET minS1=36
SET maxS1=98
SET minB1=65
SET maxB1=93

REM SAMPLE 2
SET minH2=3
SET maxH2=36
SET minS2=75
SET maxS2=100
SET minB2=32
SET maxB2=64

REM SAMPLE 3
SET minH3=8
SET maxH3=10
SET minS3=36
SET maxS3=75
SET minB3=75
SET maxB3=93

convert -size 360x1 xc: -fx "((i>=%minH1% && i<=%maxH1%)||(i>=%minH2% && i<=%maxH2%)||(i>=%minH3% && i<=%maxH3%)  )?white:black" h_lut.png
convert -size 360x1 xc: -fx "((i>=%minS1%*360/100 && i<=%maxS1%*360/100)||(i>=%minS2%*360/100 && i<=%maxS2%*360/100)||(i>=%minS3%*360/100 && i<=%maxS3%*360/100)  )?white:black" s_lut.png
convert -size 360x1 xc: -fx "((i>=%minB1%*360/100 && i<=%maxB1%*360/100)||(i>=%minB2%*360/100 && i<=%maxB2%*360/100)||(i>=%minB3%*360/100 && i<=%maxB3%*360/100)  )?white:black" b_lut.png
convert horizontals.jpg -colorspace hsb -separate test_hsb.png
convert test_hsb-0.png h_lut.png -clut test_hsb_mask1.png
convert test_hsb-1.png s_lut.png -clut test_hsb_mask2.png
convert test_hsb-2.png b_lut.png -clut test_hsb_mask3.png
convert test_hsb_mask1.png test_hsb_mask2.png test_hsb_mask3.png -evaluate-sequence multiply final_hsb_mask.png
pause

Re: Correction of -fill

Posted: 2016-05-29T15:36:49-07:00
by snibgo
Good stuff. Glad you solved it.

We don't delete solved problems, because other people may have similar problems to solve.