Skip to content
Open
Changes from all 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
12 changes: 12 additions & 0 deletions image_processing_course/ipc_s01e01.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,19 @@ def ex_2():
# TODO 4
cv2.imshow('img_color', img_color)
cv2.waitKey(1)

# Convert image to RGB for correct Matplotlib display
img_rgb = cv2.cvtColor(img_color, cv2.COLOR_BGR2RGB)

plt.figure()
plt.subplot(1, 2, 1)
plt.imshow(img_color)
plt.title('BGR (Incorrect)')

plt.subplot(1, 2, 2)
plt.imshow(img_rgb)
plt.title('RGB (Correct)')

Comment on lines +70 to +81
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The added code contains excessive blank lines that disrupt the readability of the function. Additionally, for side-by-side comparisons in Matplotlib, it is recommended to use plt.tight_layout() to ensure titles do not overlap and to specify a figsize for better visibility. Hiding the axis ticks with plt.xticks([]) and plt.yticks([]) is also a common practice for image display to focus on the content, as seen in other parts of this repository.

Suggested change
# Convert image to RGB for correct Matplotlib display
img_rgb = cv2.cvtColor(img_color, cv2.COLOR_BGR2RGB)
plt.figure()
plt.subplot(1, 2, 1)
plt.imshow(img_color)
plt.title('BGR (Incorrect)')
plt.subplot(1, 2, 2)
plt.imshow(img_rgb)
plt.title('RGB (Correct)')
# Convert image to RGB for correct Matplotlib display
img_rgb = cv2.cvtColor(img_color, cv2.COLOR_BGR2RGB)
plt.figure(figsize=(10, 5))
plt.subplot(1, 2, 1)
plt.imshow(img_color)
plt.title('BGR (Incorrect)')
plt.xticks([]), plt.yticks([])
plt.subplot(1, 2, 2)
plt.imshow(img_rgb)
plt.title('RGB (Correct)')
plt.xticks([]), plt.yticks([])
plt.tight_layout()

plt.show()
cv2.destroyAllWindows()

Expand Down