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

fix a bug when ploting a dataset with images in a range other than 0-255 #1884

Merged
merged 5 commits into from
Mar 4, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,18 @@ def output_target_format(self):
target_format = transform.output_format
return target_format

@staticmethod
def _standardize_image(image):
# Normalize the image to have minimum of 0 and maximum of 1
image_min = image.min()
image_max = image.max()
normalized_image = (image - image_min) / (image_max - image_min)
ofrimasad marked this conversation as resolved.
Show resolved Hide resolved

# Rescale the normalized image to 0-255
standardized_image = (normalized_image * 255).astype(np.uint8)

return standardized_image

def plot(
self,
max_samples_per_plot: int = 16,
Expand Down Expand Up @@ -493,6 +505,7 @@ def plot(
if image.shape[0] in (1, 3): # (C, H, W) -> (H, W, C)
image = image.transpose((1, 2, 0))

image = self._standardize_image()
ofrimasad marked this conversation as resolved.
Show resolved Hide resolved
image = image.astype(np.uint8)
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB) # Detection dataset works with BGR images, so we have to convert to RGB

Expand Down
Loading