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

Add a way to drop rows / columns of un-dividable 2D arrays using 'block_reduce' #4940

Open
CallShaul opened this issue Aug 24, 2020 · 2 comments

Comments

@CallShaul
Copy link

A suggestion:

Adding a boolean option for reducing output 1D / 2D arrays size, in case the down-sampling integer factor don't match perfectly (block_size).

@rfezzani
Copy link
Member

Hi @CallShaul, thank you for this suggestion. Can you illustrate the issue that you are solving with some lines of code?
An example can help us better understand the problem 😉

@CallShaul
Copy link
Author

CallShaul commented Aug 25, 2020

import skimage.measure as skm
import numpy as np

ds_block=(10, 10)
vid = -uint8 video data file- [x, y, time]
img = skm.block_reduce(vid[:, :, k], ds_block, func=np.mean)

As you can see in the image below the lowest row has a lower gray level values since the image wasn't perfectly divided by ds_block.

I've solved the issue slicing the extra rows / columns:
spare_rows = np.mod(vid.shape[0], ds_block[0])
spare_cols = np.mod(vid.shape[1], ds_block[1])
vid = vid[:vid.shape[0] - spare_rows]
vid = vid[:, :vid.shape[1] - spare_cols]

it will be more elegant if the block_reduce function will be able to receive a Boolean argument mentioning whether we want those lines removed or maybe even up-sample by average or something like that to fit a perfect block division.

I hope I was clear enough, I'm available for any further discussion, thanks a lot!

Shaul.

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants