regex - How to replace a float written as a string if greater or less than? -
i have image written in text format , need set pixel near black black , near white white.
the file use ʜꜱʟ colour space , looks this :
0,0: (19.2529%,100%,22.7451%) #31ff3a hsl(19.2529%,100%,22.7451%) 1,0: (18.5185%,98.1818%,21.5686%) #2ffa37 hsl(18.5185%,98.1818%,21.5686%) 2,0: (18.4524%,90.3226%,24.3137%) #2fe63e hsl(18.4524%,90.3226%,24.3137%) 3,0: (18.661%,100%,22.9412%) #30ff3b hsl(18.661%,100%,22.9412%) 4,0: (18.9891%,100%,23.9216%) #30ff3d hsl(18.9891%,100%,23.9216%) 5,0: (18.9076%,100%,23.3333%) #30ff3c hsl(18.9076%,100%,23.3333%) 6,0: (18.7107%,86.8852%,23.9216%) #30de3d hsl(18.7107%,86.8852%,23.9216%) 7,0: (18.6275%,92.7273%,21.5686%) #30ec37 hsl(18.6275%,92.7273%,21.5686%) 8,0: (19.2192%,100%,21.7647%) #31ff38 hsl(19.2192%,100%,21.7647%) 9,0: (19.2529%,100%,22.7451%) #31ff3a hsl(19.2529%,100%,22.7451%) 10,0: (19.1667%,100%,23.5294%) #31ff3c hsl(19.1667%,100%,23.5294%) 11,0: (19.209%,96.7213%,23.9216%) #31f73d hsl(19.209%,96.7213%,23.9216%) 12,0: (18.7302%,84%,24.5098%) #30d63f hsl(18.7302%,84%,24.5098%) 13,0: (18.6275%,85%,23.5294%) #30d93c hsl(18.6275%,85%,23.5294%) 14,0: (18.6728%,93.1034%,22.7451%) #30ed3a hsl(18.6728%,93.1034%,22.7451%) 15,0: (18.7316%,100%,22.1569%) #30ff39 hsl(18.7316%,100%,22.1569%) 16,0: (18.5841%,100%,22.1569%) #2fff39 hsl(18.5841%,100%,22.1569%) 17,0: (18.6186%,100%,21.7647%) #2fff38 hsl(18.6186%,100%,21.7647%) 18,0: (18.6186%,100%,21.7647%) #2fff38 hsl(18.6186%,100%,21.7647%) 19,0: (18.5841%,100%,22.1569%) #2fff39 hsl(18.5841%,100%,22.1569%) 20,0: (18.5345%,100%,22.7451%) #2fff3a hsl(18.5345%,100%,22.7451%) 21,0: (18.5345%,96.6667%,23.5294%) #2ff73c hsl(18.5345%,96.6667%,23.5294%) 22,0: (18.5345%,98.3051%,23.1373%) #2ffb3b hsl(18.5345%,98.3051%,23.1373%) 23,0: (18.5507%,100%,22.549%) #2fff3a hsl(18.5507%,100%,22.549%) 24,0: (18.5507%,100%,22.549%) #2fff3a hsl(18.5507%,100%,22.549%) 25,0: (18.5345%,98.3051%,23.1373%) #2ffb3b hsl(18.5345%,98.3051%,23.1373%) 26,0: (18.5345%,98.3051%,23.1373%) #2ffb3b hsl(18.5345%,98.3051%,23.1373%) 27,0: (18.5345%,100%,22.7451%) #2fff3a hsl(18.5345%,100%,22.7451%) 28,0: (18.5673%,100%,22.3529%) #2fff39 hsl(18.5673%,100%,22.3529%) 29,0: (18.5841%,100%,22.1569%) #2fff39 hsl(18.5841%,100%,22.1569%) 30,0: (18.5673%,100%,22.3529%) #2fff39 hsl(18.5673%,100%,22.3529%) 31,0: (18.5507%,100%,22.549%) #2fff3a hsl(18.5507%,100%,22.549%) 32,0: (18.8218%,100%,22.7451%) #30ff3a hsl(18.8218%,100%,22.7451%) 33,0: (18.7316%,100%,22.1569%) #30ff39 hsl(18.7316%,100%,22.1569%) 34,0: (18.7302%,84%,24.5098%) #30d63f hsl(18.7302%,84%,24.5098%) 35,0: (18.5824%,60%,28.4314%) #2f9949 hsl(18.5824%,60%,28.4314%)
so how (for example) can replace values above (except first 2 numbers (x,x:
) give pixel coordinate) by(0%,0%,0%) #000000 hsl(0%,0%,0%)
using vim or awk or scripting tool?
i’m thinking using light/last part of ʜꜱʟ values determining if line (except[0−9],[0−9]:
) need replaced, have no idea on how this.
you can try this:
awk ' begin { black="(0%,0%,0%) #000000 hsl(0%,0%,0%)" white="(0%,0%,100%) #ffffff hsl(0%,0%,100%)" } { line=$0 coords=$1 fs="," $0=$0 match($4, "%") sub("%.*", "", $4) if ($4 < 25) printf("%s %s\n", coords, black) else if ($4 > 75) printf("%s %s\n", coords, white) else print line fs=" " } ' <img.txt
Comments
Post a Comment