python-visualization / python-visualization/branca
Is it normal for `branca.utilities.write_png` function to normalize its values?
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 134
- Forks
- 69
- Ø Merge
- 1 Std. 10 Min.
- Gemergte PRs (30 T.)
- 1
Beschreibung
I may be wrong, but I find it weird the way branca.utilities.write_png function normalize its values.
See https://github.com/python-visualization/branca/blob/v0.8.1/branca/utilities.py#L324.
>>> import io
>>>
>>> import numpy as np
>>> import PIL.Image
>>>
>>> import branca.utilities
>>>
>>> data = np.array([[[0.74901961, 0.50196078, 1.0, 1.0], [0.25098039, 1.0, 0.74901961, 1.0]]])
>>>
>>> # Current result
>>> png_bytes = branca.utilities.write_png(data)
>>> with PIL.Image.open(io.BytesIO(png_bytes)) as image:
... np.asarray(image)
array([[[255, 127, 255, 255],
[ 85, 255, 191, 255]]], dtype=uint8)
>>>
>>> # What I expected
>>> np.rint(data * 255.0).astype(np.uint8)
array([[[191, 128, 255, 255],
[ 64, 255, 191, 255]]], dtype=uint8)
As a result, folium layers like folium.raster_layers.ImageOverlay appear brighter than I expected when passing image as an array because of the normalization.
I guess this allows users to automatically display mono rasters with a scale from minimum value as black to maximum value as white. However, for non-mono and mono rasters with a colormap, the normalization seems undesirable.
Beitragsleitfaden
Für dieses Repository ist kein Beitragsleitfaden indexiert
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne in branca/utilities.py bei write_png und verwende die verlinkte Zeile sowie das bereitgestellte NumPy/PIL-Beispiel, um die aktuelle Ausgabe zu reproduzieren. Als abgeschlossen gilt die Entscheidung über das beabsichtigte Normalisierungsverhalten für Mono-, Nicht-Mono- und farbkartierte Raster sowie dessen Überprüfung, einschließlich des gemeldeten Helligkeitseffekts in folium ImageOverlay-Layern.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- numpy, python
- Bereich
- data-visualization
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 42/100