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

how can i get ROI from nvcv.ImageBatchVarShape #154

Open
lokvke opened this issue Apr 28, 2024 · 4 comments
Open

how can i get ROI from nvcv.ImageBatchVarShape #154

lokvke opened this issue Apr 28, 2024 · 4 comments
Labels
need more info Waiting for more information from user question Further information is requested

Comments

@lokvke
Copy link

lokvke commented Apr 28, 2024

how can i get ROI from nvcv.ImageBatchVarShape, like: x_roi = x[y1:x1, y1+height, x1 + width], or x[y1:x1, y1+height, x1 + width] = x_roi...

@lokvke lokvke added the question Further information is requested label Apr 28, 2024
@bhaefnerNV
Copy link
Contributor

bhaefnerNV commented May 3, 2024

Hi @lokvke,
Thank you very much for your interest in CVCUDA!

Could you share some information on your use-case? Eg. would you like to get a ROI of the same size from an ImageBatchVarShape or would it be a different size per ImageBatchVarShape element?

@bhaefnerNV bhaefnerNV added the need more info Waiting for more information from user label May 3, 2024
@lokvke
Copy link
Author

lokvke commented May 7, 2024

Hi @lokvke, Thank you very much for your interest in CVCUDA!

Could you share some information on your use-case? Eg. would you like to get a ROI of the same size from an ImageBatchVarShape or would it be a different size per ImageBatchVarShape element?

for example, i want to put the small_imgs into large_imgs' position (100, 100)

large_imgs = nvcv.ImageBatchVarShape(100)  #  shape: (100, 1280, 720, 3)
small_imgs = nvcv.ImageBatchVarShape(100)  #  shape: (100, 120, 120, 3)
x, y = (100, 100)  # (x, y)
width, height = 120, 120
large_imgs[y:y+height, x:x+width] = small_imgs

@bhaefnerNV
Copy link
Contributor

Hi @lokvke,

then you could you the padandstack operator, which gets as an input an ImageBatchVarSahpe and outputs a Tensor of the cropped size. Below is a minimal working example

import cupy as cp
import numpy as np

import cvcuda

#dimensions
N = 100
height = 1280
width = 720
channels = 3
crop_height = 120
crop_width = 120
left = 100
top = 100

# create imagebatchvarshape
d_imgs = cvcuda.ImageBatchVarShape(N)
d_imgs.pushback([
    cvcuda.as_image(cp.array(np.random.rand(height, width, channels)))
    for _ in range(N)
])

# create output tensor
d_outs = cvcuda.Tensor(
    (N, crop_height, crop_width, channels),
    np.float32,
    "NHWC",
)

top_list = [-top] * N  # negative values do crop and positive do pad
left_list = [-left] * N  # negative values do crop and positive do pad

# device side
d_top = cvcuda.as_tensor(
    cp.array(top_list, dtype=np.int32).reshape(1, 1, len(top_list), 1), "NHWC")
d_left = cvcuda.as_tensor(
    cp.array(left_list, dtype=np.int32).reshape(1, 1, len(left_list), 1), "NHWC")

cvcuda.padandstack_into(dst=d_outs, src=d_imgs, top=d_top, left=d_left)

@lokvke
Copy link
Author

lokvke commented May 7, 2024

Hi @lokvke,

then you could you the padandstack operator, which gets as an input an ImageBatchVarSahpe and outputs a Tensor of the cropped size. Below is a minimal working example

import cupy as cp
import numpy as np

import cvcuda

#dimensions
N = 100
height = 1280
width = 720
channels = 3
crop_height = 120
crop_width = 120
left = 100
top = 100

# create imagebatchvarshape
d_imgs = cvcuda.ImageBatchVarShape(N)
d_imgs.pushback([
    cvcuda.as_image(cp.array(np.random.rand(height, width, channels)))
    for _ in range(N)
])

# create output tensor
d_outs = cvcuda.Tensor(
    (N, crop_height, crop_width, channels),
    np.float32,
    "NHWC",
)

top_list = [-top] * N  # negative values do crop and positive do pad
left_list = [-left] * N  # negative values do crop and positive do pad

# device side
d_top = cvcuda.as_tensor(
    cp.array(top_list, dtype=np.int32).reshape(1, 1, len(top_list), 1), "NHWC")
d_left = cvcuda.as_tensor(
    cp.array(left_list, dtype=np.int32).reshape(1, 1, len(left_list), 1), "NHWC")

cvcuda.padandstack_into(dst=d_outs, src=d_imgs, top=d_top, left=d_left)

Thank you for your reply, the code is about to crop a small roi from the source images. What if i want to paste small tensors or ImageBatchVarSahpe to the source ImageBatchVarSahpe, which operator can help?

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

No branches or pull requests

2 participants