Subscribe to this thread
Home - General / All posts - Trimming image?
tonyw
736 post(s)
#16-May-19 17:14

M9 question. I have orthophotos from a LiDAR fly over. Typically the orthophotos are rectangular and if the area of interest is smaller in area than the rectangle, there is a white border between the area of interest and the edge of the rectangle. In my layers I have the orthophoto above Bing Maps (satellite), the idea is that Bing maps carries on beyond the LiDAR coverage. See the attachment, I would like to eliminate the white border (blue cross hatch) so that the LiDAR more or less flows into Bing Maps or whatever layer I have below. I have read through Examples > Images, Basics > Images, Transform > Transform Templates - Images but I can't find anything that might apply. I looked at possibilities with Alpha Channels seeing if maybe the White border could be uniquely identified and isolated then treated somehow. So question, how do I eliminate or make the white border around the orthophoto transparent so the LiDAR orthophoto joins more or less seamlessly with the layer below. Thanks.

Attachments:
Trim image.JPG

tjhb
10,094 post(s)
#16-May-19 17:50

Are there any other white pixels in the orthophotos?

If not you can set alpha = 255 where RGB = (255, 255, 255).

(Even if there are other white pixels, it may not bother you to make them transparent as well, if the background is also white.)

Alternatively--and this is easier--if the white border is rectangular [and perpendicular] in the image's own projection, then you can just adjust the image Rect property. I can spell out how to do that. The nice thing is that it doesn't change the data at all, and is reversible and adjustable.

tonyw
736 post(s)
#16-May-19 19:48

Thanks Tim,

I read some more about Channels and the Alpha channel. I tried a couple of scenarios (see attached screen shots). #1 shows the orthophoto over the Bing maps layer, no changes to Channel settings. The white border shows and obscures Bing maps image in the layer below. In scenario #2, I set the Alpha channel for the Orthophoto to 255 which causes the entire orthophoto to be invisible revealing only the Bing map image below. In #3 I set all RGB and Alpha values to 255 and again the entire orthophoto is invisible revealing only the Bing map image below.

Testing some more, I can set the Alpha channel to values between say 150 and 200 and the entire Orthophoto image becomes partly transparent and you can see through the white border. However the Bing satellite image shows through.

Regarding trimming the visible rectangle, the white border is irregularly shaped, more like a hexagon so not a regular rectangle where I could adjust the rectangle size to essentially clip the visible border.

Thanks for the help.

Attachments:
Alpha 255.JPG

tjhb
10,094 post(s)
#16-May-19 20:04

OK, back soon with some code.

First, if this is a 3-channel image (is it?), we'll have to turn it into a 4-channel image so that the alpha value can be set (that is, to different values according to the values in the other three channels).

I'll post how to do that too, probably in a separate thread.

Let me know if your image already has 4 channels, since that will be quicker, just one step.

Dimitri


7,413 post(s)
#16-May-19 20:10

Are there any other white pixels in the orthophotos?

If not you can set alpha = 255 where RGB = (255, 255, 255).

By the above, I believe Tim means to use an expression. I suppose what you have is a three channel image, that is, an image where the Tile field is a 128 x 128 uint8x3 or whatever. You can create another tile field in the table, called, say, Tile2, which is a four channel tile field, 128 x 128 unint8x4. That fourth channel you can use as an alpha channel to set the alpha for each pixel individually.

Next, you copy the data for the original three channels from Tile to Tile2. You then write an expression for Tile2 which leaves the first three channels as is, but in the fourth channel sets it to 255 for pixels which have 255 in all three of the other channels and zero otherwise. That sounds complicated but if you follow the general approach given in the example topic of doing filters for RGB images it's not too difficult.

tonyw
736 post(s)
#16-May-19 20:15

In Contents > Component, the tile info shows 128x128, unit8x3, so I have a 3 channel image? I'll try to carry out the steps of creating another field in the table and populating it based on what is in the existing tile field.

Attachments:
Three channel I think.JPG

tjhb
10,094 post(s)
#16-May-19 20:40

Yes. See how you get on, I'll post on that too.

danb

2,064 post(s)
#16-May-19 20:42

In a more general case, just setting all pixels that are white to transparent isn't enough as in my experience I tend to end up making valid image pixels transparent if they they happen to be the same colour.

In M8 I tended to end up doing this manually with select touch in images (see Selection topic for M8). This tool radiates the selection out from the clicked point to grab contiguous regions of same/similar pixels (I always thought it would be good to extend this tool so that you could pre-prepare your image selection click points in a drawing for batch processing of images).

Perhaps something along these lines would be more robust? This said there is an extra level of difficulty when the image is lossy such as a JPEG where we end up with artifacts around the edge of the valid image data.


Landsystems Ltd ... Know your land | www.landsystems.co.nz

Dimitri


7,413 post(s)
#17-May-19 08:06

Removing irregularly-shaped collars from images is basically the same task as cutting some desired item, like a person or a house, out of a photo, to eliminate the background and thus allowing the use of that item as clip art.

That's a mess, exactly because of the irregularity and because of effects like JPEG halos, anti-aliasing of pixels and so on. That's why such work is mainly done manually, by hosts of graphics-editor assembly line workers. Indian contracting firms have a big presence in that business.

9 works with pixels procedurally, using expressions, scripts, and so on - not well suited to such manual workflow. Until 9 provides interactive tools like selecting a region of pixels with a polygonal "lasso", cutting and then pasting as a new image, a different tool, like 8, is the right approach.

Even better is to drill back into the food chain that provided these images. When the original photo was shot, almost certainly there was no collar, just the pixels that made up the actual photo. Most likely, that collar got added at some step after the original photo was taken. The key is to get to the photo before somebody trashed it by adding a collar. Then there's no issue.

It's like a lot of work in GIS: spending a little effort on getting clean data in the first place can save days or weeks of effort trying to repair data that's been altered into less convenient form.

danb

2,064 post(s)
#17-May-19 22:37

Well said Dimitri.

Until 9 provides interactive tools like selecting a region of pixels with a polygonal "lasso", cutting and then pasting as a new image, a different tool, like 8, is the right approach.

Very pleased to see that there is an intention to add such tools to 9. The raster/vector interactions are superb in M8 and would be wonderful to see in M9 either as is or in extended form.


Landsystems Ltd ... Know your land | www.landsystems.co.nz

Manifold User Community Use Agreement Copyright (C) 2007-2021 Manifold Software Limited. All rights reserved.