Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Row-column X, Y coordinate mix-up in RandomTiler #309

@kheffah

Description

@kheffah

Describe the bug
RandomTiler and random_choice_mask2d sometimes mixes up row-column coordinates (eg. from numpy array shapes) with x-y coordinates for the actual slide.

Software (please complete the following information):

  • OS: Ubuntu18
  • Python Version: 3.8
  • histolab version: 0.2.6

Additional context

Where I saw this:

random_choice_mask2d
These lines should probably be replaced by something like:

    true_y, true_x = np.where(binary_mask)
    loc = np.random.randint(len(true_y) - 1)

    return true_x[loc], true_y[loc]

which is also more efficient because it calls np.where only once. Test expectations will need to be re-saved etc. Current version return row-column coordinates, not x-y.

random_tile_coordinates
This "compensates" for the issue above by passing x instead of y (and y instead of x) in this line. Of course, a double bug doesn't make things right as it makes maintenance hard and error prone. But putting that aside, this doesn't actually compensate, since the row coordinate gets added to the width, and column coordinate to the height, here.

How to fix

random_choice_mask2d should return X-Y coordinates .. using something like the code snippet above. random_tile_coordinates should be kept as-is except this line, where we should reverse X and Y.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions