Page 2 of 2

Re: "even out" textures

Posted: 2013-07-12T18:32:40-07:00
by thorax
The left part has approx hue = 330 degrees, saturation = 11%, lightness = 17%.
The right part has hue = 113 degrees, sat = 30%, lightness = 24%.
how did you get those values?

Re: "even out" textures

Posted: 2013-07-13T04:04:15-07:00
by snibgo
I used Gimp's eyedropper, with a large sample radius, using HSV values. For a rough demonstration, this is sufficient. However, Gimp's Value corresponds (I think) to IM's Brightness rather than Lightness. Saturaton is probably also defined differently. A more accurate method would be to define an area and use IM, eg for the right area:

Code: Select all

D:\web\im>%IM%convert test_field.png -crop 512x1024+256+0 +repage -colorspace Lab -resize 1x1! -colorspace HSL txt:
# ImageMagick pixel enumeration: 1,1,255,hsla
0,0: ( 80, 45, 51,255)  #502D33  hsla(31.4382%,17.7493%,19.8505%,1)

D:\web\im>%IM%convert test_field.png -crop 512x1024+256+0 +repage -resize 1x1! -colorspace HSL txt:
# ImageMagick pixel enumeration: 1,1,255,hsla
0,0: ( 80, 46, 51,255)  #502E33  hsla(31.4656%,17.9477%,20.0702%,1)
The first does the averaging in Lab colorspace; the second in sRGB.

Hue is 31.4%. 31.4/100 * 360 = 113.04 degrees.
Saturation = 17.7%
Lightness = 19.8%


For the left:

Code: Select all

D:\web\im>%IM%convert test_field.png -crop 128x1024+0+0 +repage -colorspace Lab
-resize 1x1! -colorspace HSL txt:
# ImageMagick pixel enumeration: 1,1,255,hsla
0,0: (246, 16, 42,255)  #F6102A  hsla(96.5743%,6.35691%,16.585%,1)

D:\web\im>%IM%convert test_field.png -crop 128x1024+0+0 +repage -resize 1x1! -co
lorspace HSL txt:
# ImageMagick pixel enumeration: 1,1,255,hsla
0,0: (247, 16, 43,255)  #F7102B  hsla(96.6857%,6.31876%,16.701%,1)
To transform the left into the right:
Hue: 100 + 96.6 - 31.4 = 165.2
Saturation = 100 * 17.7 / 6.3 = 281
Lightness = 100 * 19.8 / 16.6 = 119

So the command should be "-modulate 119,281,165.2". This isn't very far from the estimate using Gimp of "-modulate 140,270,160.28".

Re: "even out" textures

Posted: 2013-07-13T06:01:22-07:00
by thorax
cool that is something i can calculate in a script.

now i have to look into how to determine where each "tone" area is , with the mask you told me

thank you so much !

Re: "even out" textures

Posted: 2013-07-13T09:28:08-07:00
by snibgo
For the mask, the following works. I find the average RGB value for the left side. I blur because I don't care about difference in fine detail -- detail doesn't determine if a pixel is on the left or right. For each pixel I find the differencee in hue and saturation between the pixel and this average. (The lightness doesn't discriminate, so I ignore it.)

Hue differences that are close to 0 or 100% are on the left; grays are on the right. So I solarize and multiply by 2 so zero is on the left, 100% is on the right.

Saturation difference already has zero on the left; 100% on the right.

I multiply these together. (Maybe adding would be better.)

Anything near zero is now on the left; the rest are on the right. I threshold at 2% and negate so the left is white and the right is black. This is the mask.

I use the mask to blend the original with the modulated image.

Code: Select all

%IM%convert test_field.png ^
  -blur 0x5 ^
  -write tbl.png ^
  ( +clone -fill rgb(17.6394%%,15.5306%%,15.964%%) -colorize 100 ) ^
  -colorspace HSL ^
  -compose Difference -composite ^
  -set colorspace HSL ^
  -separate +delete ^
  ( -clone 0 -equalize -solarize 50%% -evaluate Multiply 2 -write tm0.png ) -delete 0 ^
  ( -clone 0 -equalize -write tm1.png ) -delete 0 ^
  -compose Multiply -composite ^
  -threshold 2%% ^
  -negate ^
  mask.png

rem Use the mask:

%IM%convert ^
  test_field.png ^
  ( +clone -modulate 119,281,165.2 ) ^
  mask.png ^
  -compose Over -composite ^
  tBlended.png
The difference is still noticable. I wonder if the aircraft few in different seasons, and there was more leaf cover for one run?

Re: "even out" textures

Posted: 2013-07-13T17:29:58-07:00
by thorax
wow men you rock!!!

the result of this test img is very very close. There will always be some very small noticeable differences since the pictures may be taken months or years in between. But for this purpose its very close. And in the flight simulator you have limited view range , and also the view is not directly from above but instead in some kind of angle, witch makes these differences not so noticeable.

I will try this test in more images of these same grade set, and also try different grade sets.

Ill try to make a small bash script to incorporate all the concepts we have covered, and try to start automating things.

One small detail ive noticed, in the test result i see a small bluish zone just in the border area. this looks to be some leftover of the modulate process. What do you think.

As always thanks a bunch ! finally i see some hope in this problem that looked quite difficult!
regards.

Re: "even out" textures

Posted: 2013-07-13T18:06:56-07:00
by thorax
sorry i dont get how you calculate average RGB:

Code: Select all

rgb(17.6394%%,15.5306%%,15.964%%)
Im using the code above and setting colorspace to RGB but im getting different results

Re: "even out" textures

Posted: 2013-07-13T18:42:16-07:00
by snibgo
Yeah, I also get a thin blue line, which means slightly too many [EDIT: I mean too few] pixels are considered part of the right side. Try "-threshold 1%" instead.


Sorry, I missed out the first vital bit of code, the bit for "I find the average RGB value for the left side."

Code: Select all

rem Find the average RGB on the left ...

%IM%convert test_field.png ^
  -depth 16 ^
  -crop 128x1024+0+0 +repage ^
  -colorspace Lab -resize "1x1^!" -colorspace sRGB ^
  txt:

rem ... use the found average RGB in the "rgb(...)" in following:

%IM%convert test_field.png ^
  -write tbl.png ^
  ( +clone -fill rgb(17.6394%%,15.5306%%,15.964%%) -colorize 100 ) ^
{... continue as in my code above.}
The first command should give:

Code: Select all

D:\web\im>c:\im\ImageMagick-6.8.6-Q16fix\convert test_field.png   -depth 16   -crop 128x1024+0+0 +repage   -colorspace Lab -resize "1x1^!" -colorspace sRGB   txt:
# ImageMagick pixel enumeration: 1,1,65535,srgba
0,0: (11560,10178,10462,65535)  #2D2827C228DE  srgba(17.6394%,15.5306%,15.964%,1)
I've converted to Lab space, averaged the pixels, and converted that single pixel back to sRGB. I've shown the values I get: 17.6394%, 15.5306%, 15.964%, and 1. These are for channels RGBA. The A (Alpha) doesn't matter. I manually copied the RGB values to the next command. Normally a script would do this.

These are RGB values, meaning "Red, Green and Blue". But they are in sRGB colorspace, not RGB colorspace. Sorry for the confusion.

The conversion to Lab and back is hardly necessary; it makes little difference.

Re: "even out" textures

Posted: 2013-07-14T08:30:57-07:00
by thorax
i get a totally different result form that line of code:

Code: Select all

alejandro@desktop:~$ convert test.png -depth 16 -crop 128x1024+0+0 +repage -colorspace Lab -resize 1x1! -colorspace sRGB txt:
# ImageMagick pixel enumeration: 1,1,65535,srgba
0,0: ( 1591, 1264, 1363,65535)  #063704F00553  srgba(2.42771%,1.92874%,2.0798%,1)

Re: "even out" textures

Posted: 2013-07-14T10:12:20-07:00
by snibgo
That image, with RGB values about 2%, must be very dark on the left. Put it up somewhere, if you like, and I'll take a look at it.

The image I am using is the one linked to in your second post, "This is a sample texture that features the boundary. The end result should be all green, the same tone".

Incidentally, what IM version are you using? I'm on v6.8.6-0, on Windows 7. Some versions yield slightly different numbers, but shouldn't be far out.

Re: "even out" textures

Posted: 2013-07-14T14:03:55-07:00
by thorax
im using the same image as you.. this is weird.. i even re downloaded the image from the host to discard any host format change that may be going on.

im on linux, my im version is:

Code: Select all

alejandro@desktop:~$ convert -version
Version: ImageMagick 6.6.0-4 2012-05-02 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2010 ImageMagick Studio LLC
Features: OpenMP 
lets try this one:

Image

re downloading from the host, i get:

Code: Select all

alejandro@desktop:~$ convert new-test.png -depth 16 -crop 64x1024+0+0 +repage -colorspace Lab -resize 1x1! -colorspace sRGB txt:
# ImageMagick pixel enumeration: 1,1,65535,srgba
0,0: ( 3603, 2766, 2571,65535)  #0E130ACE0A0B  srgba(5.49783%,4.22065%,3.92309%,1)
note that ive made the selected zone smaller

Re: "even out" textures

Posted: 2013-07-14T14:36:44-07:00
by thorax
ok ive build from source last version and now:

Code: Select all

alejandro@desktop:~$ convert new-test.png -depth 16 -crop 64x1024+0+0 +repage -colorspace Lab -resize 1x1! -colorspace sRGB txt:
# ImageMagick pixel enumeration: 1,1,65535,srgba
0,0: (17295,15135,14566,65535)  #438F3B1F38E6  srgba(26.3905%,23.0945%,22.2263%,1)
for the other img i get:

Code: Select all

alejandro@desktop:~$ convert test2.png -depth 16 -crop 128x1024+0+0 +repage -colorspace Lab -resize 1x1! -colorspace sRGB txt:
# ImageMagick pixel enumeration: 1,1,65535,srgba
0,0: (11560,10178,10462,65535)  #2D2827C228DE  srgba(17.6394%,15.5306%,15.964%,1)
witch is consistent.

i guess the problem was an old version

Re: "even out" textures

Posted: 2013-07-14T15:32:40-07:00
by snibgo
Yes, 6.6.0 is very old. I suggest you don't use it.

I happen to have a copy of 6.6.0-8, and it gives the same incorrect values that you found. It gives correct results if I don't convert to Lab and back.

Re: "even out" textures

Posted: 2013-07-14T16:27:05-07:00
by thorax
Ok, im not sure if you read bash, but ive wrapped up all the notes and came up with a script.

The only manual imput is the AREA_A and AREA_B . Ill look in the future how to automatize this as well, but for this test well have to do it manually

Code: Select all

#!/bin/bash

ARGS=2

if [ $# -ne $ARGS ]
then
	echo "Usage: `basename $0` {input-texture} {output-texture}"
else

	IN="$1"
	OUT="$2"
	AREA_A="1024x2048+0+0"
	AREA_B="400x2048+1560+0"
	#AREA_B="512x512+64+0"

	#RGB='17.6394%%,15.5306%%,15.964%%'
	#MODULATE='119,281,165.2'


	HSL_A=`convert "$IN" -crop "$AREA_A" +repage -colorspace Lab -resize 1x1! -colorspace HSL txt: | tail -1 | awk '{print $NF}' |sed 's/,1)//g' | sed 's/hsla(//g' | sed 's/%//g' | sed 's/,/ /g'`
	#HSL_A=`convert "$IN" -crop "$AREA_A" +repage -resize 1x1! -colorspace HSL txt: | tail -1 | awk '{print $NF}'| sed 's/,1)//g' | sed 's/hsla(//g' | sed 's/%//g' | sed 's/,/ /g'`

	H_A=`echo "$HSL_A" | awk '{print $1}'`
	S_A=`echo "$HSL_A" | awk '{print $2}'`
	L_A=`echo "$HSL_A" | awk '{print $3}'`

	HSL_B=`convert "$IN" -crop "$AREA_B" +repage -colorspace Lab -resize 1x1! -colorspace HSL txt: | tail -1 | awk '{print $NF}' |sed 's/,1)//g' | sed 's/hsla(//g' | sed 's/%//g' | sed 's/,/ /g'`
	#HSL_B=`convert "$IN" -crop "$AREA_B" +repage -resize 1x1! -colorspace HSL txt: | tail -1 | awk '{print $NF}'| sed 's/,1)//g' | sed 's/hsla(//g' | sed 's/%//g' | sed 's/,/ /g'`

	H_B=`echo "$HSL_B" | awk '{print $1}'`
	S_B=`echo "$HSL_B" | awk '{print $2}'`
	L_B=`echo "$HSL_B" | awk '{print $3}'`

	MODULATE_H=$(perl -e "print ( 100 + "$H_A" - "$H_B" )")
	MODULATE_S=$(perl -e "print ( 100 * "$S_B" / "$S_A" )")
	MODULATE_L=$(perl -e "print ( 100 * "$L_B" / "$L_A" )")

	MODULATE="$MODULATE_L,$MODULATE_S,$MODULATE_H"
	echo "$MODULATE"

	RGB_A=`convert "$IN"  -depth 16 -crop "$AREA_A" +repage -colorspace Lab -resize 1x1! -colorspace sRGB  txt:| tail -1 | awk '{print $NF}' | sed 's/,1)//g' | sed 's/srgba(//g'`
	RGB_B=`convert "$IN"  -depth 16 -crop "$AREA_B" +repage -colorspace Lab -resize 1x1! -colorspace sRGB  txt:| tail -1 | awk '{print $NF}' | sed 's/,1)//g' | sed 's/srgba(//g'`
	echo "$RGB_A"


	convert "$IN" -blur 0x5 -write tbl.png \( +clone -fill rgb\("$RGB_A"\) -colorize 100 \) -colorspace HSL -compose Difference -composite -set colorspace HSL -separate +delete \( -clone 0 -equalize -solarize 50%% -evaluate Multiply 2 -write tm0.png \) -delete 0 \( -clone 0 -equalize -write tm1.png \) -delete 0 -compose Multiply -composite -threshold 2%% -negate mask.png

	convert "$IN" \( +clone -modulate "$MODULATE" \) mask.png -compose Over -composite "$OUT"

	rm tbl.png tm0.png tm1.png mask.png

fi

Im seeing that this works well for the test image posted above, but ive selected other images and its not working very well for those. Im not sure what values to play with but im noticing the mask is not being created correctly. Maybe i need to change the threshold ?

see some more sample images:

Image Image Image

Image Image

Re: "even out" textures

Posted: 2013-07-14T19:08:54-07:00
by snibgo
I said earlier: "Hue: 100 + 96.6 - 31.4 = 165.2". I think that was wrong.

From http://www.imagemagick.org/script/comma ... p#modulate : Hue rotation:
0 means -180 degrees, -50% of full circle;
100 means 0 degrees, 0%;
200 means +180 degrees, 50%;
300 means 360 degrees, 100%.

If we want to rotate by F % of full circle, we need H = 100 + F * 2.
Eg to rotate by 30% of full circle, H = 100 + 60 = 160.

To transform from F0 % to F1 %, we take F = (F1 - F0) modulus 100.
Eg from F0=96.6, F1=31.3, then F = 31.3 - 96.6 = -65.2 which, modulus 100, is 34.8.

So:
H = 100 * F * 2
H = 100 * 34.8 * 2
H = 169.6

By coincidence, this is close to my mistaken 165.2.