Skip to content

Commit

Permalink
Merge branch 'main' into multiprocess
Browse files Browse the repository at this point in the history
  • Loading branch information
Victorlouisdg committed Feb 22, 2024
2 parents 6cd7645 + 4ccce6c commit 6352d99
Showing 1 changed file with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,32 @@
)


def crop(image: HWCImageType, x: int, y: int, h: int, w: int) -> HWCImageType:
def crop(image: HWCImageType, x: int, y: int, w: int, h: int) -> HWCImageType:
"""Crop a smaller rectangular part out of an image. We use the same rectangle convention as OpenCV.
Args:
image (HWCImageType): the image to crop
x: the x-coordinate of the top-left corner of the crop, measured in pixels starting from the left edge of the image.
y: the y-coordinate of the top-left corner of the crop, measured in pixels starting from the top edge of the image.
h: the height of the crop in pixels.
w: the width of the crop in pixels.
h: the height of the crop in pixels.
"""
# Note that the first index of the array is the y-coordinate, because this indexes the rows of the image and the y-axis runs from top to bottom.
if len(image.shape) == 2:
return image[y : y + h, x : x + w].copy()

return image[y : y + h, x : x + w, :].copy()


class Crop(ImageTransform):
""""""

def __init__(self, input_shape: ImageShapeType, x: int, y: int, h: int, w: int):
def __init__(self, input_shape: ImageShapeType, x: int, y: int, w: int, h: int):
super().__init__(input_shape)
self.x = x
self.y = y
self.h = h
self.w = w
self.h = h

@property
def shape(self) -> ImageShapeType:
Expand All @@ -39,7 +42,7 @@ def shape(self) -> ImageShapeType:
return self.h, self.w, c

def transform_image(self, image: HWCImageType) -> HWCImageType:
return crop(image, self.x, self.y, self.h, self.w)
return crop(image, self.x, self.y, self.w, self.h)

def transform_point(self, point: ImagePointType) -> ImagePointType:
x, y = point
Expand Down

0 comments on commit 6352d99

Please sign in to comment.