Skip to content

Commit 87c816d

Browse files
committed
Don't normalize Image.histogram/1
1 parent 102c786 commit 87c816d

File tree

7 files changed

+65
-24
lines changed

7 files changed

+65
-24
lines changed

CHANGELOG.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
11
# Changelog
22

3+
## Image 0.62.0
4+
5+
This is the changelog for Image version 0.62.0 released on August 7th, 2025. For older changelogs please consult the release tag on [GitHub](https://github.com/elixir-image/image/tags)
6+
7+
### Bug Fixes
8+
9+
* `Image.histogram/1` is fixed to not normalize histogram entries. Therefore the histogram now returns correct pixel counts.
10+
11+
* Added an example for `Image.histogram/1` to illustrate what data is returned and how to interpret it.
12+
313
## Image 0.61.1
414

5-
This is the changelog for Image version 0.61.1 released on JJuly 14th, 2025. For older changelogs please consult the release tag on [GitHub](https://github.com/elixir-image/image/tags)
15+
This is the changelog for Image version 0.61.1 released on July 14th, 2025. For older changelogs please consult the release tag on [GitHub](https://github.com/elixir-image/image/tags)
616

717
### Bug Fixes
818

lib/image.ex

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7145,7 +7145,7 @@ defmodule Image do
71457145
Returns the histogram for an image.
71467146
71477147
The histogram is returned as a `t:Vimage.t/0`
7148-
that is a 255 by 255 image with the same numbers of
7148+
that is a 255 by 1 pixel image with the same numbers of
71497149
bands as the source image.
71507150
71517151
### Argument
@@ -7161,22 +7161,52 @@ defmodule Image do
71617161
### Notes
71627162
71637163
The returned image is is organized
7164-
as a 256x256 pixel image with
7164+
as a 256x1 pixel image with
71657165
the same number of bands as the original
71667166
image.
71677167
7168-
Each pixel on the image returns the count
7168+
Each pixel on the image returns the *count*
71697169
of pixels in the original image that are
71707170
in that 1/256th part of the image.
71717171
7172+
Each band is separated into 1/256ths individually.
7173+
For an RGB image the first number of the
7174+
pixel element of the histogram is the count of the
7175+
number of pixels in the red band, the second the count
7176+
of pixels in the green band and the third a count of
7177+
the pixels in the blue band.
7178+
7179+
### Example
7180+
7181+
iex> image = Image.new!(3, 3, color: [0, 128, 0])
7182+
iex> {:ok, _histogram} = Image.histogram(image)
7183+
7184+
# Here is the returned list (which is just a way of
7185+
# visualing the histogram). The first entry of `[9, 0, 9]`
7186+
# is saying "in the first 1/256th of values, there are 9 pixels
7187+
# in the red band and 9 pixels in the blue band". Later on,
7188+
# in the 128th entry, we can see there are 9 pixels in the green
7189+
# band and none in the red and blue bands.
7190+
7191+
histogram |> Image.to_nx!() |> Nx.to_list()
7192+
[
7193+
[
7194+
[9, 0, 9],
7195+
[0, 0, 0],
7196+
...
7197+
[0, 9, 0],
7198+
...
7199+
[0, 0, 0],
7200+
[0, 0, 0]
7201+
]
7202+
]
7203+
71727204
"""
71737205
@doc subject: "Clusters", since: "0.3.0"
71747206

71757207
@spec histogram(Vimage.t()) :: {:ok, Vimage.t()} | {:error, error_message()}
71767208
def histogram(%Vimage{} = image) do
7177-
image
7178-
|> Operation.hist_find!()
7179-
|> Operation.hist_norm()
7209+
Operation.hist_find(image)
71807210
end
71817211

71827212
@delta_e_versions [:de76, :de00, :decmc]

mix.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
defmodule Image.MixProject do
22
use Mix.Project
33

4-
@version "0.61.1"
4+
@version "0.62.0"
55

66
@app_name "image"
77

mix.lock

Lines changed: 15 additions & 14 deletions
Large diffs are not rendered by default.

test/image_test.exs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,8 @@ defmodule Image.Test do
145145
out_path = Temp.path!(suffix: ".png", basedir: dir)
146146
assert :ok = Vimage.write_to_file(out, out_path)
147147

148-
# Image.preview out
149-
# Image.preview Image.open!(validate_path)
148+
Image.preview out
149+
Image.preview Image.open!(validate_path)
150150

151151
# Image.write!(out, validate_path)
152152
assert_images_equal(out_path, validate_path, 2.0)
2.61 KB
Loading
0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)