Embedding multiple masks in an image

Started by bigben, October 11, 2007, 07:28:08 PM

Previous topic - Next topic

bigben

Following on from my Blue Marble experiment I couldn't help but think about using these images as masks. While the resolution is relatively low, the colours are reasonably realistic and there are no clouds, so they should be useful for defining broad environmental regions. Rather than generate additional images, it should be possible to compare the colour within the image to a reference colour using functions and set a deviation range on which to generate a mask. Should be technically possible, although the network might get a little complicated and performance will need to be tested.

So far so good, but what about the masks I painstakingly generate from landsat images... These are much higher resolution (10-15m after reprojecting to UTM), have unrealistic colours and do contain some clouds.  File size has always been an issue with greyscale image masks derived from these. Each project involved calculating a total image size (Mb) to be divided up amongst the masks. The criteria for selecting which resolution to make a mask got a little complex, with a particular mask often being made up of a combination of other masks of different resolutions.

Combining the two methods I'm going to test the following workflow:

  • Create multi-layered PSD document with high res masks as normal
  • Insert each mask in a single channel of an RGB image with a different grey level for each mask.
  • Non-overlapping masks added to the same channel with different grey levels
  • Overlapping masks added to different channels
  • Load image into TG2
  • Set up functions to split image to RGB scalars and then generate masks based on the greyscale values used for each mask (with some tolerance to include anti-aliaing of the image.

In theory this should make it possible to add several high resolution masks to an image for the same cost as 3 greyscale images.  Something to play with over the weekend.  :)

dhavalmistry

man...where the hell do u get all these ideas??....
"His blood-terragen level is 99.99%...he is definitely drunk on Terragen!"

bigben

Some people play brain training games on their Nintendo DS on the train... I play with TG2  ;D.  I have a varied and nerdy background (astronomy, geology, botany/zoology, scientific photography etc....) and with TG2 I get to draw on all of the stuff I've learnt and connect it together to solve problems (and occasionally make a cool pic). It's quite rewarding to actually use all this stuff I crammed into my head and that helps keep me on a roll  ;)

Njen

At the very least, one can put 3 different masks into each of the individual colour channels of red, green and blue of any image format. While only limiting the number of masks per image to three, it's superior in a few ways:

* PSD is a proprietary format
* All image formats use RGB channels and can all be used in this method
* The technology to read the RGB colour channels separately is very simple
* Easier to manage than individual layers within a PSD

bigben

Quote from: njen on October 12, 2007, 02:31:33 AM
At the very least, one can put 3 different masks into each of the individual colour channels of red, green and blue of any image format. While only limiting the number of masks per image to three, it's superior in a few ways:

* PSD is a proprietary format
* All image formats use RGB channels and can all be used in this method
* The technology to read the RGB colour channels separately is very simple
* Easier to manage than individual layers within a PSD

I was referring to multi-layered PSD images mainly as my source for generating masks. I generate multiple layers for different components and then combine for a final mask output. This speeds the workflow as you don't have to be 100% accurate for each mask type. e.g. quick tree distribution - carefully drawn rivers and roads... or slope mask used to mask manually drawn rivers (preventing you from drawing rivers up the side of valleys as satellite images are not 100% accurate on terrain)... more in the blurb to follow... ;)

bigben

Well as usual I start with the most optimistic ideas and then work my way back to what is actually practical/feasible. The results so far:

Image size/format

Using RGB images was a bit of a silly idea as it's really trying to do too much. The main reason is that TG's limits with loading images seem to relate more to Mb than pixels.  You can therefore load a lager greyscale image than a RGB image i.e. higher resolution masks. Using different greyscale values within a single image for different masks is still a good idea though. The image I added to this project covers the south island and is 7500 x 8600 pixels. The equivalent blue marble texture is only 2700 x 3100 (full resolution).

[sidetrack] For those trying to push the limits of loading large RGB textures for planetary renders, you might try separating the channels to greyscale images and then reconstructing the colour in TG2 using a build colour node. It my be possible to get a 70% increase in image width unless you reach a memory limit before this. [/sidetrack]

Masking Regions

OK, so which masks to combine. Once again, I got too ambitious and tried to mask two non-adjacent areas. I was already concerned that it might not work as expected due to anti-aliasing creating a range of greyscale values at the border of two pixel values in the image. This concern was well founded as this render shows, but at this stage it's good to see when things don't work.

What did work, though is a substantial increase in resolution of the surfacing. You can see part of the lake from the blue marble texture protruding from the lake on the left... and of course you can make out portions of where a wide river bed would flow betweent the pink masked areas.The trick to using this successfully then is going to be in carefully choosing which adjacent features to include in a single mask. e.g. water, beach, rocks, all grass, green grass.  In my TG0.9 Grampians project I had these equivalent masks as separate images and didn't have enough RAM to have them all as high res. Some of the masks were at lower res, with careful surface order selection compensating for the lack of resolution (e.g. low resolution beach overlayed at edges by hig res lakes and grass)

There will still be some edge effects, so selecting features that will not look out of place when in close proximity in these areas will also help, as well as some additional mask adjustments to provide some extra breakup of the edges.

Tonal masking

While anti-aliasing creates some minor complications at the edges of these masks it also has many benefits. The first is that it greatly increases the apparent resolution of the mask (at the cost of some fine detail). It also increases the apparent tonal range, with an 8 bit greyscale image behaving more like a 16-bit image when you make adjustments to it in TG. It would therefore be reasonably practical to combine "hard" masks with tonal masks in the on image. e.g. all grass (hard mask, pixel value 128) and green grass (tonal mask, pixel value range 32-96). The base grass texture is for dead grass, overlayed with a texture for green grass blended by the green grass mask... Using conditional nodes and colour adjust nodes to extract the tonal range from the mask image and then adjusting it back to the full tonal range. The smoothing from anti-aliasing will add in the intermediate tones.

While this approach my not be as good as using full tonal images, it is all part of a balancing act. It's a compromise between resolution and the number of masks required. By reducing the number of masks required you can increase their resolution which in my experience is usually more beneficial than accurate tonal values.

Conditional nodes.

Had to have a play with htese  ;)  A few things didn't go quite to plan. To get the conditional node to work I had to convert the colour to a scalar first which wasn't expected. The output of the conditional node was somewhat pixellated but that was because of the way I had set it up (outputs of 1 or 0). To smooth it I could have set a colour adjusted image as the true output, but by the time you set that up for additional masks it would be easier to use colour adjust nodes in conjunction with add/sutract/multiply scalar nodes to construct the separate masks.

The Boolean conditional mask didn't seem to work at all???
Conditional: Image = 1, true = 1, else = 0 worked
Boolean conditional: Image > 0.9 didn't work

In situations where some pixellation is not an issue (distributions of large objects), using an image without anti-aliasing and conditional nodes could provide a quick method of setting up masks.

Very promising so far.... definitely worth some more experimentation.


dhavalmistry

"His blood-terragen level is 99.99%...he is definitely drunk on Terragen!"

monks

This is great work BB. This is the kind of scales that ME-DEM will want to work at.

monks

bigben

#9
Recovering from some odd system problems... had to download again and reinstall.

But prior to that, I had made some more progress and it's working reasonably well. 7 masks in one image. I've manually drawn some rivers in but the resolution is insufficient for them to actually show up (requires >1 pixel wide to account for anti-aliasing)  Other masks I've made at the full resolution of the landsat images were OK, but there's no way I'm going to get a 15m resolution image to cover this large an area.  (resolution of mask image here is only 90m)

I'll work on a closer view after I sort out a few more technical details. Already identified a few settings that need to be changed in the image map node to make the pixel values correlate better to the black and white levels in the colour adjust nodes. I'm a little surprised (pleasantly) that I haven't run into memory issues yet but I'm sure I'll be able to find that limit without too much trouble.

More results and details later.

bigben

#10
Back up and running. Here's a low res comparison showing the difference in resolution between the blue marble texture and my greyscale mask. I got the rivers back with a bit more tweaking of the colour adjust settings, although the main problem was a slope restriction.

The screengrab shows the links from the image map to the surface shaders.  This is a very basic setup to test the principle. To add a bit more variation I'd probably start by using the mask output as a blending shader for a fractal to use as the breakup for the surfaces.

[attachthumb=#3]

The main glitches in a method like this are where adjacent masked areas do not contain sequential greyscale values. In the worst case scenario of white pixels next to black, anti-aliasing will smooth the border to potentially create a full greyscale range.  The various colour adjustments will then result in narrow bands of every surface layer along this border.  How much of a problem this is depends on how close you want to get with the camera and the resolution of the mask.  This should be taken into consideration when choosing greyscale values for the mask regions, so that in some cases the banding will appear natural.  In this scene the progression from white to black is : Water > Rock > Sand > Dark dead grass/scrub > Light dead grass > Green Grass > Trees.  Layer order will also come into play but this will vary from scene to scene.

The other thing to remember is that creating masks is a very laborious process, particularly rivers, which require extensive checking and usually require a lot of manual drawing. 

[attachthumb=#4]

Lakes are a breeze now. I use a slope map from GM to select the lakes (magic wand with a tolerance of 1, not antialiased... lakes are white and the banks are not.), and the landsat image is used to locate them. This method was particularly useful for this mask image because there were some clouds over some of the larger lakes at the south end.

Still a few technical issues to sort out. Need to check Data is Linear in the Colour tab of the Image map node to start with or it's very hard getting the right colour adjust settings.

Backing the camera up a bit and running a larger, high quality render.  8)

bigben

Stopped the render as it displays enought for demonstration purposes. Bear in mind that the surfacing was left deliberately basic to clearly show the distributions.  From here I have to go back to a basic test image to produce a clip to extract masks from 10% increments in greyscale values.... and then make a full resolution mask of this area.

This result is definitely good enough for me to continue developing it.

nvseal

This is looking fantastic. When can we see one from higher up?

bigben

Running a smaller version of frame 1 (the original orbital render). There were some clouds in the lower right of the south island so it will be interesting to see how these glitches in the mask appear from this distance.

bigben

Just had a quick look in Google Earth to check my interpretation of the landsat image...  Looks like I was reasonably correct in choosing areas of green vegetation. Landsat images can be hard to interpret on their own as bare rock, areas burnt out by bush fires and lush grass can all be bright pink.

The larger lake is also lighter in all of the satellite imagery which could be easily handled by using white for dark lakes and 90% for light lakes in the mask image. Any edge effects on the dark lakes would just look like shallow water, and in those cases where there is some detail in the satellite imagery from different water depths, these could be added in to the mask as intermediate tones using a third colour adjust shader to create a tonal mask...