AtthalaricNero commited on
Commit
1590197
·
1 Parent(s): d5f00c3

Remove brightness normalization function and update preprocessing pipeline to directly use normalized image data

Browse files
Files changed (1) hide show
  1. app.py +1 -17
app.py CHANGED
@@ -41,22 +41,6 @@ CLASS_NAMES = [
41
  "Salak",
42
  ]
43
 
44
- def normalize_brightness(img):
45
- """Normalisasi brightness dan contrast untuk konsistensi"""
46
- # Convert ke LAB color space
47
- lab = cv2.cvtColor(img, cv2.COLOR_RGB2LAB)
48
- l, a, b = cv2.split(lab)
49
-
50
- # Apply CLAHE (Contrast Limited Adaptive Histogram Equalization) pada channel L
51
- clahe = cv2.createCLAHE(clipLimit=2.0, tileGridSize=(8, 8))
52
- l = clahe.apply(l)
53
-
54
- # Merge kembali
55
- lab = cv2.merge([l, a, b])
56
- normalized = cv2.cvtColor(lab, cv2.COLOR_LAB2RGB)
57
-
58
- return normalized
59
-
60
  def extract_color_histogram(img, bins=(8, 8, 8)):
61
  hist = cv2.calcHist([img], [0, 1, 2], None, bins, [0, 256, 0, 256, 0, 256])
62
  hist = cv2.normalize(hist, hist).flatten()
@@ -76,7 +60,7 @@ def preprocessing_pipeline(pil_img):
76
  img = np.array(pil_img.convert('RGB'))
77
  img = cv2.resize(img, (100, 100), interpolation=cv2.INTER_AREA)
78
 
79
- img_float = normalize_brightness(img)
80
  img_uint8 = (img_float * 255).astype(np.uint8)
81
 
82
  feat_color = extract_color_histogram(img_uint8)
 
41
  "Salak",
42
  ]
43
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
  def extract_color_histogram(img, bins=(8, 8, 8)):
45
  hist = cv2.calcHist([img], [0, 1, 2], None, bins, [0, 256, 0, 256, 0, 256])
46
  hist = cv2.normalize(hist, hist).flatten()
 
60
  img = np.array(pil_img.convert('RGB'))
61
  img = cv2.resize(img, (100, 100), interpolation=cv2.INTER_AREA)
62
 
63
+ img_float = img.astype(np.float32) / 255.0
64
  img_uint8 = (img_float * 255).astype(np.uint8)
65
 
66
  feat_color = extract_color_histogram(img_uint8)