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

Indexing video with binary mask #5376

Open
1 task done
Tomsen1410 opened this issue Mar 15, 2024 · 1 comment
Open
1 task done

Indexing video with binary mask #5376

Tomsen1410 opened this issue Mar 15, 2024 · 1 comment
Assignees
Labels
question Further information is requested

Comments

@Tomsen1410
Copy link

Describe the question.

Is it possible to index data nodes using a binary mask within a pipeline?

More precisely, I want to remove possible black bars on top and at the bottom of videos. For that, I compute all rows in a video with all-blac pixels and get a binary mask:

mask = fn.reductions.sum(video, axes=[0, 2, 3]) > 0

How can I now use the mask to crop the video accordingly?

Check for duplicates

  • I have searched the open bugs/issues and have found no duplicates for this bug report
@Tomsen1410 Tomsen1410 added the question Further information is requested label Mar 15, 2024
@JanuszL
Copy link
Contributor

JanuszL commented Mar 15, 2024

Hi @Tomsen1410,

I think you can try something like this:

    mask = fn.reductions.sum(video, axes=[0, 2, 3]) > 0
    shape = fn.reductions.sum(fn.cast(mask, dtype=types.INT32), dtype=types.INT32)
    mask_shifted = fn.slice(fn.cast(mask, dtype=types.UINT8), 0, shape, axes=[0]) == 0
    anchor = fn.reductions.sum(fn.cast(mask_shifted, dtype=types.INT32), dtype=types.INT32)
    video_trim = fn.slice(video, anchor, shape, axes=[1])

as long as the content is bigger than the black bars.
You can also try nonsilent_region operation that was designed for the audio signal in mind but should work in your case as well

    anchor, shape = fn.nonsilent_region(fn.cast(mask, dtype=types.UINT8), reset_interval=1, window_length=1)

It would be best for you to check which one performs better with your data.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants