Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[EXPERIMENTAL] v.colors: Histogram equalization #1392

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

HuidaeCho
Copy link
Member

Lightness (in HSL)-based color histogram equalization. Calculates probability using feature areas (no cells in vector), but I may not merge it if I fail to fix the following issue.

v.colors map=censusblk_swwake use=attr column=TOTAL_POP color=blues -e

seems to work,
image

but

v.colors map=censusblk_swwake use=attr column=TOTAL_POP color=rainbow -e

doesn't work.

@HuidaeCho HuidaeCho marked this pull request as draft February 21, 2021 02:21
@HuidaeCho HuidaeCho changed the title v.colors: EXPERIMENTAL histogram equalization [EXPERIMENTAL] v.colors: Histogram equalization Feb 21, 2021
@HuidaeCho
Copy link
Member Author

Method

  1. RGB => HSL
  2. Sort areas by L in an ascending order
  3. For each area, calculate the cumulative area (sum_area) and probability (L) by sum_area / total_area
  4. Original (H, S) and new L from step 3 => RGB

Issues
This method seems to work for monotonic color maps, but a color map such as rainbow has only two lightnesses 0.5 and 1 and it doesn't really make much sense to histogram equalize two intensities. Maybe, I should do color-averaged equalization.

@HuidaeCho
Copy link
Member Author

HuidaeCho commented Feb 21, 2021

In fact, these two commands don't work either:

v.colors map=censusblk_swwake use=attr column=TOTAL_POP color=blues -g
v.colors map=censusblk_swwake use=attr column=TOTAL_POP color=blues -a

because Rast_log_colors() and Rast_abs_log_colors() interpolates categories, which doesn't make sense for vector maps. Vector maps require exact categories in the color file, it seems?

@cmbarton cmbarton marked this pull request as ready for review February 22, 2021 17:20
@cmbarton
Copy link
Contributor

This does not work correctly on my Mac. I just cloned and complied it within the past hour. I tested it with the NC census block data. A good place to look is with the TOTAL_POP attribute because it has an area much higher than any others: cat=1319. Checking the histogram equalization box gives unexpected and incorrect results with a multi-color table (check out one of the viridis tables or GRASS bgyr). It seems initially to work with a single color gradient like blues or reds. But even these are incorrect. TOTAL_POP for cat=1319 should be the most intense color but it is not. It looks exactly the same as some other areas like cat=1364. You can try the same equalizations on a raster version of the census block vector area map and it looks correct.

@HuidaeCho
Copy link
Member Author

This does not work correctly on my Mac. I just cloned and complied it within the past hour. I tested it with the NC census block data. A good place to look is with the TOTAL_POP attribute because it has an area much higher than any others: cat=1319. Checking the histogram equalization box gives unexpected and incorrect results with a multi-color table (check out one of the viridis tables or GRASS bgyr). It seems initially to work with a single color gradient like blues or reds. But even these are incorrect. TOTAL_POP for cat=1319 should be the most intense color but it is not. It looks exactly the same as some other areas like cat=1364. You can try the same equalizations on a raster version of the census block vector area map and it looks correct.

I see. I think this PR needs some (a lot of?) work. It gets tricky to implement histogram equalization for vector features. BTW, have you tried -a or -g? Do they work for you?

v.colors map=censusblk_swwake use=attr column=TOTAL_POP color=blues -a
v.colors map=censusblk_swwake use=attr column=TOTAL_POP color=blues -g

@HuidaeCho HuidaeCho marked this pull request as draft March 7, 2021 05:27
@HuidaeCho
Copy link
Member Author

I see. I think this PR needs some (a lot of?) work. It gets tricky to implement histogram equalization for vector features. BTW, have you tried -a or -g? Do they work for you?

v.colors map=censusblk_swwake use=attr column=TOTAL_POP color=blues -a
v.colors map=censusblk_swwake use=attr column=TOTAL_POP color=blues -g

Nope. They don't work (#1432 (comment)).

@neteler neteler added enhancement New feature or request vector Related to vector data processing labels Dec 9, 2021
@neteler neteler added this to the 8.2.0 milestone Dec 9, 2021
@wenzeslaus wenzeslaus modified the milestones: 8.2.0, 8.4.0 Feb 27, 2022
@wenzeslaus wenzeslaus modified the milestones: 8.3.0, 8.4.0 Feb 10, 2023
@HuidaeCho HuidaeCho self-assigned this Mar 6, 2024
@wenzeslaus wenzeslaus modified the milestones: 8.4.0, Future Apr 27, 2024
@neteler
Copy link
Member

neteler commented Jun 16, 2024

@HuidaeCho would you mind to rebase this PR?

@github-actions github-actions bot added C Related code is in C module labels Jun 17, 2024
@HuidaeCho HuidaeCho force-pushed the v_colors_histogram_equalization branch from 295a8d9 to 9380697 Compare June 17, 2024 03:29
@HuidaeCho
Copy link
Member Author

@HuidaeCho would you mind to rebase this PR?

@neteler Please try it.

@neteler
Copy link
Member

neteler commented Jun 18, 2024

I have tested it again successfully with the following test:

# main
grass ~/grassdata/nc_spm_08_grass7/user1
g.region vector=censusblk_swwake -p
d.mon  wx0

# show original, suboptimal color table
d.vect censusblk_swwake

# apply histogram equalization
v.colors map=censusblk_swwake use=attr column=TOTAL_POP color=blues -e

# show with improved color table
d.vect censusblk_swwake 

# restore original color table
v.colors map=censusblk_swwake use=attr column=TOTAL_POP color=blues 

d.redraw

Which edge cases shall be tested?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C Related code is in C enhancement New feature or request module vector Related to vector data processing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants