smistad / FAST

A framework for high-performance medical image processing, neural network inference and visualization
https://fast.eriksmistad.no
BSD 2-Clause "Simplified" License
433 stars 101 forks source link

PatchGenerator - Whole Slide image - Get position of the patch (x,y) #209

Open LouisStefanuto opened 1 month ago

LouisStefanuto commented 1 month ago

Is your feature request related to a problem? Please describe. No pb. Just looking for a feature. I am generating patches from a TIFF image.

Describe the solution you'd like I would like to be able to get the pixel position of the patch, let's say the (x,y) of the top left pixel Ideally it would be something like:

for patch in fast.DataStream(patchGenerator):
  x, y = patch.x, patch.y

Do you have an idea of how it can/should be implemented? Currently I have access to the path number

for i, patch in enumerate(fast.DataStream(patchGenerator)):

I could compute the position using the stride, tile size and padding, but I am hoping it is already implemented somewhere.

Are you willing to contribute to the implementation of this feature N/A

smistad commented 1 month ago

Hi, this is possible to extract, but I agree it should be more accessible and documented.

Here is how you can do it today (ref https://github.com/smistad/FAST/pull/206/files) :

patch_width, patch_height = int(patch.getFrameData("patch-width")), int(patch.getFrameData("patch-height"))
patch_overlap_x, patch_overlap_y = int(patch.getFrameData("patch-overlap-x")), int(patch.getFrameData("patch-overlap-y"))
x_pos = int(patch.getFrameData("patchid-x")) * (patch_width - patch_overlap_x * 2) + patch_overlap_x 
y_pos = int(patch.getFrameData("patchid-y")) * (patch_height - patch_overlap_y * 2) + patch_overlap_y
LouisStefanuto commented 1 month ago
  1. Thanks for answering so fast
  2. Thanks a lot, it works perfectly
  3. Wonderful library, I love it 😍
LouisStefanuto commented 1 month ago

Before closing the issue, I don't see it in the doc. Is it coming in the next release ?

smistad commented 1 month ago

Just leave the issue open so I can remember to make a single property of this instead of needing to calculate it.

I just haven't updated the documentation yet.

Thanks for your feedback 🙂