Skip to content

Commit

Permalink
[#2] add: 이진화 Otsu 임계값 출력 기능
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryuchanghoon committed Feb 4, 2025
1 parent 067257f commit c87431b
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions binari_global_thresholding.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import cv2
import numpy as np
import matplotlib.pyplot as plt


image_path = "test.jpg"
Expand All @@ -14,5 +15,22 @@
cv2.namedWindow("Manual Thresholding", cv2.WINDOW_NORMAL)
cv2.imshow('Manual Thresholding', combined_image)

# ------ Otsu's Thresholding -------

_, otsu_binary = cv2.threshold(image, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)

hist = cv2.calcHist([image], [0], None, [256], [0, 256])


plt.plot(hist, color='black')
plt.title('Grayscale Histogram')
plt.xlabel('Pixel Value')
plt.ylabel('Frequency')
plt.show()


cv2.namedWindow('Otsu thresholding', cv2.WINDOW_NORMAL)
cv2.imshow('Otsu thresholding', otsu_binary)

cv2.waitKey(0)
cv2.destroyAllWindows()

0 comments on commit c87431b

Please sign in to comment.