MetaCell / salk-interactive-atlas

1 stars 0 forks source link

Heatmap edges contrast #108

Open neuroBazzi opened 2 years ago

neuroBazzi commented 2 years ago

Client request: being able to see the edges of the slice. This is already implemented but simply not visible because the background is black and so are the areas of the slices where there are no cell (so no difference between the background and the inside of the slice where there are no cells). Consider either changing the background or the color associated with 0 in the heatmap to non black (to grey-ish?)

afonsobspinto commented 2 years ago

Atlas has a volume which has the 2D representation of the cord. (Needs to be scaled the same way as the heatmap) Select middle-point/first plane/last plane (or potentially all together) of subsection

Also have a look at https://stackoverflow.com/questions/54703674/how-do-i-make-my-numpy-image-take-an-alpha-channel-value-in-python. (Change black to transparent in the heatmap image)

afonsobspinto commented 2 years ago

Latest from the heatmap: 1 - I calculate the probability_map in the subdivision space:

bins = get_subdivision_bin(atlas, 'C1')
np.histogramdd(points, bins=bins, density=normalise)

2 - I get the accumulated probability map by summing all the slices in the subdivision space and divide by the amount of slices

    acc = np.zeros(probability_map[0].shape, dtype=float)
    for slice in probability_map:
        acc += slice
    return acc / len(probability_map)

3 - I scale the accumulated_probability_map so that the max value represents white

scaled_image = 256 / np.max(img) * img

4 - I make black pixels transparent: https://stackoverflow.com/questions/54703674/how-do-i-make-my-numpy-image-take-an-alpha-channel-value-in-python

Here's the result without smoothing: result

Here's the result with smoothing: result

afonsobspinto commented 2 years ago

The reason why the smoothing version looks funny is because we are removing just the pure black pixels not the 'blackish' pixels. We can add a sort of black threshold and achieve something like the following, but it's hard to get something perfect result

afonsobspinto commented 2 years ago

with @zsinnema help I was able to produce the following: gray_test We can also play with the smoothing: (75, 50, 25 respectively)

gray_test gray_test gray_test

zsinnema commented 2 years ago

@neuroBazzi what "smoothing" do you like (btw it's a Gaussian blur): 100, 75, 50, 25?

PS: the image is transparent so on white backgrounds the white in the "middle" looks like the background because we have a "dark" theme imo this will be no issue. if we want to switch to a "light" theme we should invert the color white --> black

neuroBazzi commented 2 years ago

@zsinnema I think 50 would be the best.

afonsobspinto commented 2 years ago

Adding the atlas.annotation as background:

background: 100% test3

background: 50% test3

background: 25% test3

background: 12.5% test3

background: 6.25% test3