Skip to content

Commit

Permalink
Fix incorrect image tensor shape
Browse files Browse the repository at this point in the history
  • Loading branch information
akash-akya committed Oct 15, 2023
1 parent cd98ba2 commit 96668db
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
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

0 comments on commit 96668db

Please sign in to comment.