Filtering by RGB range of values

491 views
Skip to first unread message

Alejandro Hinojosa

unread,
Jul 15, 2023, 7:49:41 AM7/15/23
to last...@googlegroups.com
Hello,

I have unsuccessfully tried to filter a photogrammetric point cloud based on a range of RGB values.  I want to filter RGB values of water coverage from color infra-red camera. Could you provide some examples in how to connect filtering options (and, or) ? 

This is the cmd line not working for me

las2las -i *1.laz -odir out -odix f ^
 -keep_RGB_blue 27136 47616 ^
 -keep_RGB_red 15360 23040 -filter_and ^
 -keep_RGB_green 28160 38400 -filter_and  -olaz

I tried with scaled-down RGB values (0..255), but still not working. Lasinfo shows min max values of RGB in the full-scale color range:
       R 4608 64768
        G 4864 62720
        B 6656 65024

although with lasview i option, point attributes shows a range of 0..255 color values. 

Another option would be to use the -keep_NDVI_intensity_is_NIR -1.0 0.0?

Thanks

--
Alejandro Hinojosa

Jochen Rapidlasso

unread,
Jul 19, 2023, 4:09:27 PM7/19/23
to LAStools - efficient tools for LiDAR processing
Hi Alejandro,
it should work as you tried. I did this test:

lasinfo -i  colored.laz

...
Color R 2560 65280
        G 2304 65280
        B 1280 65280
...

:: get some sample points

las2las -i colored.laz -o tmp.laz -stop_at_point 10
las2txt -i tmp.laz -o tmp.txt -parse xyzRGB

85130.03 79586.09 325.98 13056 18688 23552
85130.35 79586.16 325.92 12288 17920 22528 --> red test
85130.68 79586.23 325.89 12800 18432 23296 --> blue test
85130.96 79586.29 325.82 11008 16128 20480
85131.26 79586.35 325.80 22784 25088 23552 --> green test
85131.57 79586.42 325.74 34048 35840 29440
85131.88 79586.48 325.69 32768 34048 27648
85130.29 79585.73 325.92 11776 17664 22528
85130.61 79585.80 325.87 12032 17664 22528
85130.90 79585.86 325.84 12032 17152 21760

:: single color test
las2las -i  tmp.laz -o tmp2.laz -keep_RGB_red 12288 12288
las2las -i  tmp.laz -o tmp2.laz -keep_RGB_green 25088 25088
las2las -i  tmp.laz -o tmp2.laz -keep_RGB_blue 23296 23296

-> each 1 point, ok

combine this results:

las2las -i  tmp.laz -o tmp2.laz -keep_RGB_red 12288 12288 -keep_RGB_green 25088 25088 -keep_RGB_blue 23296 23296

-> empty result, so by default it will be combined as "AND".

las2las -i  tmp.laz -o tmp2.laz -keep_RGB_red 12288 12288 -keep_RGB_green 25088 25088 -filter_or -keep_RGB_blue 23296 23296 -filter_or

-> empty result -> it is not a OR filter

las2las -i  tmp.laz -o tmp2.laz -keep_RGB_red 12288 12288 -keep_RGB_green 25088 25088 -filter_and -keep_RGB_blue 23296 23296 -filter_and

-> result 3 points -> this is the one!

What do you mean with "not working for me": What is the output and what did you expect?
If you can not fix it: Can you send a small sample of the file and I will further analyze.

Thanks,

Jochen @rapidlasso

Alejandro Hinojosa

unread,
Jul 20, 2023, 2:05:35 AM7/20/23
to last...@googlegroups.com
Hello Jochen,

Thank you for looking into my color filtering problem, but not sure the result is what I looking for. I am looking for overlapping ranges in the color space.

I want to filter out points that correspond to a water surface from a color infra-red camera. As you know, the water surface  is not a good target for photogrammetric reconstruction, so I want to remove this cover type from the point cloud.

In the color space, my data has a specific signature for the water. If I do a scatter plot of the color vectors, the water coverage will form a cluster, I could define and select the colour range for the water cover on the cluster and then filter out using the range values. The range of values would have to be met for each color component, so filter would need to be connected with AND. This is the target filter I was looking for.

I cut a sample of the point cloud for you to explore, it is on the link below


You will see the cloud is wrongly classified (from Pix4D), water coverage as buildings, perhaps I should look into reclassifying from scratch and try to search for a scheme that would work. 

At the end, what worked for me was using a nice feature Martin added to filter points based on NDVI values for color infra-red point clouds, NDVI is calculated on the fly and allows filtering based on the index value. Negative values would correspond to water. Here is the statement that worked for me.

las2las -i in.laz -o out.laz  -keep_NDVI_from_CIR -0.1 1.0  

This would not work in RGB point clouds, so I am still interested in filtering points from water coverages based on RGB clusters in the colour space. 

Thanks

Alejandro

--
Download LAStools at
https://rapidlasso.de
Manage your settings at
https://groups.google.com/g/lastools/membership
---
You received this message because you are subscribed to the Google Groups "LAStools - efficient tools for LiDAR processing" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lastools+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lastools/b603c1e9-98e1-4ad6-b31a-433f9f645b7cn%40googlegroups.com.


--
Alejandro Hinojosa
CICESE

Jochen Rapidlasso

unread,
Jul 21, 2023, 3:04:15 AM7/21/23
to LAStools - efficient tools for LiDAR processing
Hi Alejandro,
ok, I think I got your problem now.
What you want is selecting points by hue/color value, not only RGB value.
Therefore we have to convert the RGB value to a HSL (hue/color, saturation, lightness) model and then allow to filter by H,S,L.
I think this would be a general useful extension of LAStools - we will add this feature soon to the LAStools filters...

Best regards,

Jochen

Andi Rapidlasso

unread,
Jan 15, 2024, 3:39:53 PMJan 15
to LAStools - efficient tools for LiDAR processing
Hi Alejandro,
this is done now.
With the current release (240115) it is able now to filter by HSV or HSL color model.
Please see this article about the details.

Andi

Alejandro Hinojosa

unread,
Jan 17, 2024, 2:31:53 AMJan 17
to last...@googlegroups.com
Hi Andi,

Thanks for the update on adding this useful filter to LAStools. I will try it, first  I will have to convert RGB ranges of the target cover to HSV model. Discover the target cover color in HSV space, then a (2d, 3d) scatter plot would help to search for clusters of target cover type.

Even though the new addition, I would like to filter by RGB color ranges, have not been able to filter successfully in RGB model. Do you have examples of how to filter with RGB ranges? Previously I  provided a sample for you to test, could prepare more examples if needed.

My target surface is water from photogrammetric point clouds, to remove point clouds of water cover (-drop...), it introduces many positional errors. I am working with tidal flats and channels landscapes during low tides. To reconstruct channel networks from DEMs. I've tested the hydro flattening in las2dem using the -lakes and -creeks options to mask out water. Still need to generate somehow the shapefile to filter out water and assign a height to the surface to work properly. 

 Is it important if color is coded in 8 or 16 bits?

Thanks

Alejandro

Andi Rapidlasso

unread,
Jan 17, 2024, 2:38:09 AMJan 17
to LAStools - efficient tools for LiDAR processing
Hi Alejandro,
thank you for the feedback. About the color depth: As we wrote in this article this is automatically detected.

Andi

Alejandro Hinojosa

unread,
Mar 26, 2024, 11:19:24 AMMar 26
to Alejandro Hinojosa, last...@googlegroups.com, Jessica Lizbeth Alvarez Garcia
Hi Andi, Jochen

To inform you that I revisited the topic of filtering photogrammetric point clouds using color filters to exclude water coverage, and would like to share my experience. First, I tried the RGB filters using ranges from two bands and learned how to connect (and) the restrictions. 

I had to find the range of values of the color vector of the target cover (water). I used a scatter plot of the corresponding orhophoto (see image attached). The color ranges from orthophoto and in the point cloud were 8 bit (0..255).  The 8 bit ranges had to be scaled to 16 bit (*256) as the arguments for the filter command.

ScatterPlots1.jpg

Here is the command line that worked for me on RGB ranges using only bands red and green. 

las2las -i in.laz  -o  out.laz -drop_RGB_red 35584 43776 -drop_RGB_green 39424 46848 -filter_and 

and the result in images (2 tests). For better results on left image, I had to relax the RGB ranges.

RGB_Filters.jpg

 We also tried the HLS color space method kindly prepared by Jochen and Andi, thanks. To accomplish this task, You had to have a range in hue values (min max) for the filters. I did a clip of the target surfaces (water) on the source point cloud, and on the resulting clipped cloud I  ran a las2txt64 to extract the HSL vector as indicated in the article.  

A comment that the new addition only works for 64 bit of the latest releases. The RGB to HLS conversion in las2txt64 and the HLS filtering in las2las64. Here is the command for RGB to HLS conversion

las2txt64 -i clip.laz -parse xyz(HSL) -sep comma -o out.csv
las2txt64 -i clip.laz -parse xyz(hsl) -sep comma -o out1.csv  #  for normalized results

With the output, you need to find the hue min and max to apply the filter. With excel you can sort the hue column. Here is the filter command with one sample area

las2las64 -i in.laz -o out.laz -drop_HSL_hue 53d 87d

FiltrandoAguaHue1.JPG

Beautiful. Another sample, the command line with different hue range 

las2las64 -i in.laz -o out.laz -drop_HSL_hue 149d 176d 

and the output comparison.
FiltrandoAguaHue.JPG


It is easier with hue ranges than with RGB. It worked great, thanks Jochen and Andi. 

Alejandro

Jochen Rapidlasso

unread,
Mar 26, 2024, 11:30:47 AMMar 26
to LAStools - efficient tools for LiDAR processing
Hi Alejandro,
thanks for the positive feedback!

Jochen @rapidlasso

Reply all
Reply to author
Forward
0 new messages