Skip to content

Using the result of an indexing expression as output argument in Python is broken #204

@crisluengo

Description

@crisluengo

In Python, using the latest release, this does not work:

dip.Infimum(dist2[left:right, top:bottom], distance_function, out=dist2[left:right, top:bottom])

Here, dist2 is an SFLOAT image, and distance_function is a standard 64-bit float NumPy array.

What happens is that the output image is being reforged to DFLOAT, the common format for the two input images. This means of course that the result is not being written into dist2 as expected by the user.

The work-around is either

dist2[left:right, top:bottom] = dip.Infimum(dist2[left:right, top:bottom], distance_function)

or

tmp = dist2[left:right, top:bottom]
tmp.Protect()
dip.Infimum(tmp, distance_function, out=tmp)

Neither is pretty.

I don't know how to fix this issue currently. We cannot automatically protect any image created by indexing, can we?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions