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

Fix incorrect image tensor shape #129

Merged
merged 1 commit into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/vix/tensor.ex
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ defmodule Vix.Tensor do
@typedoc """
Struct to hold raw pixel data returned by the Libvips along with metadata about the binary.

`:names` will always be `[:width, :height, :bands]`
`:names` will always be `[:height, :width, :bands]`
"""

@type t() :: %__MODULE__{
Expand All @@ -41,7 +41,7 @@ defmodule Vix.Tensor do

defstruct data: nil,
shape: {0, 0, 0},
names: [:width, :height, :bands],
names: [:height, :width, :bands],
type: {}

@doc """
Expand Down
4 changes: 2 additions & 2 deletions lib/vix/vips/image.ex
Original file line number Diff line number Diff line change
Expand Up @@ -679,8 +679,8 @@ defmodule Vix.Vips.Image do
with {:ok, binary} <- write_to_binary(image) do
tensor = %Vix.Tensor{
data: binary,
shape: {width(image), height(image), bands(image)},
names: [:width, :height, :bands],
shape: {height(image), width(image), bands(image)},
names: [:height, :width, :bands],
type: Vix.Tensor.type(image)
}

Expand Down
2 changes: 1 addition & 1 deletion lib/vix/vips/mutable_image.ex
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ defmodule Vix.Vips.MutableImage do
end

@doc """
Return the shape of the umage as
Return the shape of the image as
`{width, height, bands}`.
"""
def shape(%MutableImage{pid: pid}) do
Expand Down
2 changes: 1 addition & 1 deletion test/vix/vips/image_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ defmodule Vix.Vips.ImageTest do
{:ok, im} = Image.new_from_file(img_path("black.jpg"))
assert {:ok, %Vix.Tensor{} = tensor} = Image.write_to_tensor(im)

assert tensor.shape == {Image.width(im), Image.height(im), Image.bands(im)}
assert tensor.shape == {Image.height(im), Image.width(im), Image.bands(im)}

expected_bin_size = Image.width(im) * Image.height(im) * Image.bands(im)
assert tensor.data == :binary.copy(<<0>>, expected_bin_size)
Expand Down