Basing Rules off of Color Map?

1062
4
Jump to solution
05-14-2013 10:08 AM
NathanBrigmon
New Contributor
Good Afternoon Everyone,

I recently went over one of the CityEngine Tutorials where you learn to base rules off of maps using the amount of "brightness" from the map. I believe it was the "Reporting" Tutorial where you base heights and building types off of two different maps/images.

My question is: can the same idea be done based off of a colored map (i.e. Land Use Map)? If I built a CGA rule for Single Family, Multi-Family, Commercial, etc. all with variations, could I assign one to "Blue" ("#0000FF"), one to "Yellow" ("#FFFF00"), etc?

Any ideas would be greatly appreciated. Thanks!

Nathan
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
MatthiasBuehler1
Frequent Contributor
hi !


images consist of r,g,b components. if you have a standard 8 bit image ( 3 channels ), each one color is represented in a range with 256 brightness values ( for each color component ).

e.g.

255,0,0 is pure red.
0,255,0 is pure green.
..



sampling attributes can be done differently, to get a proper attribute mapping. but in the end, you're always querying those r,g,b colors and putting them in a new range, default is 0 - 1, as you've seen in the tutorials.

what you sample is up to you :
whether you're working with the image brightness ( 0 - 1 ), hue, saturation or with just the individual color components of that image.

since usually you want to map one information to 1 color value, it is easiest to use just 'brightness' and not colors per se, because they contain 3 components.

I usually create 1 greyscale map for each attribute I want to map, mapped by brightness.

The issue with sampling colors is that you have to find specific colors within 3 components.
e.g.
if color.r > 0.9 && color.g < 0.1 && color.b < 0.1
then it must be 'reddish'. testing this component-wise is a pain.

The additional factor which makes this tricky is that CityEngine samples image color values ( the integer values 0 - 255 ) and 'casts' them as float values ( values with decimals ), which can produce tiny imprecisions of the color values. e.g. color.r = 0.999878453 instead of 1. Those potential errors have to be handled in case statements, which you find a bit confusing and unintuitive. [But that's how it is currently.]

Thus, by far the best thing is to encode any info you need simply in greyscale values ( e.g. rgb 0,0,0  //  10,10,10 // 58,58,58 , ..).


Hope this makes sense. Let me know if it does .. 😉

Matt

View solution in original post

0 Kudos
4 Replies
MatthiasBuehler1
Frequent Contributor
Hi Nathan,


Yes, this is possible. You can map ANY attribute value that way.

That's the beauty of it. 😉

Nice, huh ?

It's best you play with those tutorial files ( they're downloadable ).

M.
0 Kudos
NathanBrigmon
New Contributor
Thanks Matthias,

Do you know of a good example? I have been using this one Land Use map and cannot figure out how to calculate the RGB value from the map and assign it an attribute. Would that entail using the channel "hue"? I guess I'm not too familiar with this type of coding...

I've gone through all 15 tutorials and none address this specific issue. I'd also be fine with browsing a troubleshooting/help page if you happen to know of one.

Thanks again!

Nathan
0 Kudos
MatthiasBuehler1
Frequent Contributor
hi !


images consist of r,g,b components. if you have a standard 8 bit image ( 3 channels ), each one color is represented in a range with 256 brightness values ( for each color component ).

e.g.

255,0,0 is pure red.
0,255,0 is pure green.
..



sampling attributes can be done differently, to get a proper attribute mapping. but in the end, you're always querying those r,g,b colors and putting them in a new range, default is 0 - 1, as you've seen in the tutorials.

what you sample is up to you :
whether you're working with the image brightness ( 0 - 1 ), hue, saturation or with just the individual color components of that image.

since usually you want to map one information to 1 color value, it is easiest to use just 'brightness' and not colors per se, because they contain 3 components.

I usually create 1 greyscale map for each attribute I want to map, mapped by brightness.

The issue with sampling colors is that you have to find specific colors within 3 components.
e.g.
if color.r > 0.9 && color.g < 0.1 && color.b < 0.1
then it must be 'reddish'. testing this component-wise is a pain.

The additional factor which makes this tricky is that CityEngine samples image color values ( the integer values 0 - 255 ) and 'casts' them as float values ( values with decimals ), which can produce tiny imprecisions of the color values. e.g. color.r = 0.999878453 instead of 1. Those potential errors have to be handled in case statements, which you find a bit confusing and unintuitive. [But that's how it is currently.]

Thus, by far the best thing is to encode any info you need simply in greyscale values ( e.g. rgb 0,0,0  //  10,10,10 // 58,58,58 , ..).


Hope this makes sense. Let me know if it does .. 😉

Matt
0 Kudos
NathanBrigmon
New Contributor
Thanks!

I'll try this route and see what I come up with.
0 Kudos