Skip to content

Commit

Permalink
swap order of args in Crop
Browse files Browse the repository at this point in the history
  • Loading branch information
Victorlouisdg committed Feb 22, 2024
1 parent 2ebeea3 commit 3fb51d7
Showing 1 changed file with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
)


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.
return image[y : y + h, x : x + w, :].copy()
Expand All @@ -23,12 +23,14 @@ def crop(image: HWCImageType, x: int, y: int, h: int, w: int) -> HWCImageType:
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
print("w", w)
print("h", h)
self.w = w
self.h = h

@property
def shape(self) -> ImageShapeType:
Expand All @@ -39,7 +41,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 3fb51d7

Please sign in to comment.