jarondon82 commited on
Commit
d54d7a7
·
verified ·
1 Parent(s): f1d9f4b

colocando textos explicativos

Browse files

agregando comentarios y textos explicativos

Files changed (1) hide show
  1. app.py +93 -7
app.py CHANGED
@@ -92,22 +92,35 @@ def main():
92
  st.subheader("Processed Image")
93
 
94
  if processing_option == "Basic Operations":
 
 
 
 
 
 
 
 
 
 
95
  operation = st.sidebar.selectbox(
96
  "Select Operation",
97
  ["Resize", "Rotate", "Flip", "Brightness/Contrast", "Color Quantization"]
98
  )
99
 
100
  if operation == "Resize":
 
101
  scale = st.sidebar.slider("Scale Factor", 0.1, 2.0, 1.0)
102
  processed_img = cv2.resize(original_img, None, fx=scale, fy=scale)
103
 
104
  elif operation == "Rotate":
 
105
  angle = st.sidebar.slider("Angle", -180, 180, 0)
106
  center = (original_img.shape[1] // 2, original_img.shape[0] // 2)
107
  matrix = cv2.getRotationMatrix2D(center, angle, 1.0)
108
  processed_img = cv2.warpAffine(original_img, matrix, (original_img.shape[1], original_img.shape[0]))
109
 
110
  elif operation == "Flip":
 
111
  flip_option = st.sidebar.selectbox("Flip Direction", ["Horizontal", "Vertical", "Both"])
112
  if flip_option == "Horizontal":
113
  processed_img = cv2.flip(original_img, 1)
@@ -117,6 +130,11 @@ def main():
117
  processed_img = cv2.flip(original_img, -1)
118
 
119
  elif operation == "Brightness/Contrast":
 
 
 
 
 
120
  brightness = st.sidebar.slider("Brightness", -100, 100, 0)
121
  contrast = st.sidebar.slider("Contrast", -100, 100, 0)
122
 
@@ -139,16 +157,28 @@ def main():
139
  processed_img = cv2.addWeighted(processed_img, alpha_c, processed_img, 0, gamma_c)
140
 
141
  elif operation == "Color Quantization":
 
142
  k = st.sidebar.slider("Number of Colors", 2, 16, 8)
143
  processed_img = apply_color_quantization(original_img, k)
144
 
145
  elif processing_option == "Filtering":
 
 
 
 
 
 
 
 
 
 
146
  filter_type = st.sidebar.selectbox(
147
  "Select Filter",
148
  ["Blur", "Gaussian", "Median", "Bilateral", "Custom Kernel"]
149
  )
150
 
151
  if filter_type == "Custom Kernel":
 
152
  kernel_size = st.sidebar.slider("Kernel Size", 3, 7, 3, step=2)
153
  kernel_type = st.sidebar.selectbox("Kernel Type", ["Sharpen", "Edge Detection", "Emboss"])
154
 
@@ -161,21 +191,39 @@ def main():
161
 
162
  processed_img = cv2.filter2D(original_img, -1, kernel)
163
  else:
 
164
  kernel_size = st.sidebar.slider("Kernel Size", 3, 15, 3, step=2)
165
 
166
- if filter_type == "Blur":
167
- processed_img = cv2.blur(original_img, (kernel_size, kernel_size))
168
- elif filter_type == "Gaussian":
169
- processed_img = cv2.GaussianBlur(original_img, (kernel_size, kernel_size), 0)
170
- elif filter_type == "Median":
171
- processed_img = cv2.medianBlur(original_img, kernel_size)
172
- elif filter_type == "Bilateral":
173
  d = st.sidebar.slider("d", 1, 15, 9)
174
  sigma_color = st.sidebar.slider("Sigma Color", 1, 255, 75)
175
  sigma_space = st.sidebar.slider("Sigma Space", 1, 255, 75)
176
  processed_img = cv2.bilateralFilter(original_img, d, sigma_color, sigma_space)
 
 
 
 
 
 
 
177
 
178
  elif processing_option == "Color Spaces":
 
 
 
 
 
 
 
 
 
 
179
  color_space = st.sidebar.selectbox(
180
  "Select Color Space",
181
  ["RGB", "HSV", "LAB", "YCrCb", "Individual Channels"]
@@ -239,6 +287,15 @@ def main():
239
  processed_img = cv2.morphologyEx(original_img, cv2.MORPH_BLACKHAT, kernel)
240
 
241
  elif processing_option == "Edge Detection":
 
 
 
 
 
 
 
 
 
242
  detector = st.sidebar.selectbox(
243
  "Select Detector",
244
  ["Canny", "Sobel", "Laplacian", "Scharr"]
@@ -273,6 +330,19 @@ def main():
273
  processed_img = np.uint8(np.absolute(processed_img))
274
 
275
  elif processing_option == "Feature Detection":
 
 
 
 
 
 
 
 
 
 
 
 
 
276
  detector = st.sidebar.selectbox(
277
  "Select Detector",
278
  ["Harris Corner", "Shi-Tomasi", "FAST"]
@@ -307,6 +377,14 @@ def main():
307
  cv2.drawKeypoints(original_img, kp, processed_img, color=(0, 0, 255))
308
 
309
  elif processing_option == "Histogram Operations":
 
 
 
 
 
 
 
 
310
  operation = st.sidebar.selectbox(
311
  "Select Operation",
312
  ["Show Histogram", "Equalization", "CLAHE"]
@@ -332,6 +410,14 @@ def main():
332
  processed_img = apply_histogram_equalization(original_img, "CLAHE")
333
 
334
  elif processing_option == "Advanced Effects":
 
 
 
 
 
 
 
 
335
  effect = st.sidebar.selectbox(
336
  "Select Effect",
337
  ["Pencil Sketch", "Cartoon", "HDR Effect"]
 
92
  st.subheader("Processed Image")
93
 
94
  if processing_option == "Basic Operations":
95
+ st.sidebar.markdown("""
96
+ ### Basic Operations
97
+ Transform your image with fundamental operations:
98
+ - **Resize**: Scale the image up or down
99
+ - **Rotate**: Rotate the image by any angle
100
+ - **Flip**: Mirror the image horizontally or vertically
101
+ - **Brightness/Contrast**: Adjust image lighting
102
+ - **Color Quantization**: Reduce the number of colors
103
+ """)
104
+
105
  operation = st.sidebar.selectbox(
106
  "Select Operation",
107
  ["Resize", "Rotate", "Flip", "Brightness/Contrast", "Color Quantization"]
108
  )
109
 
110
  if operation == "Resize":
111
+ st.sidebar.markdown("Adjust the scale factor to resize the image. Values > 1 enlarge, values < 1 shrink.")
112
  scale = st.sidebar.slider("Scale Factor", 0.1, 2.0, 1.0)
113
  processed_img = cv2.resize(original_img, None, fx=scale, fy=scale)
114
 
115
  elif operation == "Rotate":
116
+ st.sidebar.markdown("Rotate the image by specifying an angle in degrees. Positive values rotate counter-clockwise.")
117
  angle = st.sidebar.slider("Angle", -180, 180, 0)
118
  center = (original_img.shape[1] // 2, original_img.shape[0] // 2)
119
  matrix = cv2.getRotationMatrix2D(center, angle, 1.0)
120
  processed_img = cv2.warpAffine(original_img, matrix, (original_img.shape[1], original_img.shape[0]))
121
 
122
  elif operation == "Flip":
123
+ st.sidebar.markdown("Mirror the image in different directions.")
124
  flip_option = st.sidebar.selectbox("Flip Direction", ["Horizontal", "Vertical", "Both"])
125
  if flip_option == "Horizontal":
126
  processed_img = cv2.flip(original_img, 1)
 
130
  processed_img = cv2.flip(original_img, -1)
131
 
132
  elif operation == "Brightness/Contrast":
133
+ st.sidebar.markdown("""
134
+ Adjust image brightness and contrast:
135
+ - **Brightness**: Negative values darken, positive values brighten
136
+ - **Contrast**: Negative values decrease contrast, positive values increase it
137
+ """)
138
  brightness = st.sidebar.slider("Brightness", -100, 100, 0)
139
  contrast = st.sidebar.slider("Contrast", -100, 100, 0)
140
 
 
157
  processed_img = cv2.addWeighted(processed_img, alpha_c, processed_img, 0, gamma_c)
158
 
159
  elif operation == "Color Quantization":
160
+ st.sidebar.markdown("Reduce the number of colors in the image. Lower values create more poster-like effects.")
161
  k = st.sidebar.slider("Number of Colors", 2, 16, 8)
162
  processed_img = apply_color_quantization(original_img, k)
163
 
164
  elif processing_option == "Filtering":
165
+ st.sidebar.markdown("""
166
+ ### Image Filtering
167
+ Apply different filters to smooth or enhance the image:
168
+ - **Blur**: Simple averaging filter
169
+ - **Gaussian**: Weighted gaussian smoothing
170
+ - **Median**: Good for removing salt-and-pepper noise
171
+ - **Bilateral**: Edge-preserving smoothing
172
+ - **Custom Kernel**: Apply specific filter effects
173
+ """)
174
+
175
  filter_type = st.sidebar.selectbox(
176
  "Select Filter",
177
  ["Blur", "Gaussian", "Median", "Bilateral", "Custom Kernel"]
178
  )
179
 
180
  if filter_type == "Custom Kernel":
181
+ st.sidebar.markdown("Apply predefined kernel effects. Larger kernel sizes create stronger effects.")
182
  kernel_size = st.sidebar.slider("Kernel Size", 3, 7, 3, step=2)
183
  kernel_type = st.sidebar.selectbox("Kernel Type", ["Sharpen", "Edge Detection", "Emboss"])
184
 
 
191
 
192
  processed_img = cv2.filter2D(original_img, -1, kernel)
193
  else:
194
+ st.sidebar.markdown("Adjust kernel size to control the strength of the filter effect.")
195
  kernel_size = st.sidebar.slider("Kernel Size", 3, 15, 3, step=2)
196
 
197
+ if filter_type == "Bilateral":
198
+ st.sidebar.markdown("""
199
+ Bilateral Filter Parameters:
200
+ - **d**: Diameter of pixel neighborhood
201
+ - **Sigma Color**: Filter sigma in color space
202
+ - **Sigma Space**: Filter sigma in coordinate space
203
+ """)
204
  d = st.sidebar.slider("d", 1, 15, 9)
205
  sigma_color = st.sidebar.slider("Sigma Color", 1, 255, 75)
206
  sigma_space = st.sidebar.slider("Sigma Space", 1, 255, 75)
207
  processed_img = cv2.bilateralFilter(original_img, d, sigma_color, sigma_space)
208
+ else:
209
+ if filter_type == "Blur":
210
+ processed_img = cv2.blur(original_img, (kernel_size, kernel_size))
211
+ elif filter_type == "Gaussian":
212
+ processed_img = cv2.GaussianBlur(original_img, (kernel_size, kernel_size), 0)
213
+ elif filter_type == "Median":
214
+ processed_img = cv2.medianBlur(original_img, kernel_size)
215
 
216
  elif processing_option == "Color Spaces":
217
+ st.sidebar.markdown("""
218
+ ### Color Spaces
219
+ Convert the image between different color representations:
220
+ - **RGB**: Standard Red-Green-Blue color space
221
+ - **HSV**: Hue-Saturation-Value, useful for color segmentation
222
+ - **LAB**: Perceptually uniform color space
223
+ - **YCrCb**: Used in video encoding
224
+ - **Individual Channels**: View color components separately
225
+ """)
226
+
227
  color_space = st.sidebar.selectbox(
228
  "Select Color Space",
229
  ["RGB", "HSV", "LAB", "YCrCb", "Individual Channels"]
 
287
  processed_img = cv2.morphologyEx(original_img, cv2.MORPH_BLACKHAT, kernel)
288
 
289
  elif processing_option == "Edge Detection":
290
+ st.sidebar.markdown("""
291
+ ### Edge Detection
292
+ Different methods to detect edges in the image:
293
+ - **Canny**: Advanced edge detector with thresholds
294
+ - **Sobel**: Directional gradient detection
295
+ - **Laplacian**: Detect edges using 2nd derivatives
296
+ - **Scharr**: More accurate gradient calculation
297
+ """)
298
+
299
  detector = st.sidebar.selectbox(
300
  "Select Detector",
301
  ["Canny", "Sobel", "Laplacian", "Scharr"]
 
330
  processed_img = np.uint8(np.absolute(processed_img))
331
 
332
  elif processing_option == "Feature Detection":
333
+ st.sidebar.markdown("""
334
+ ### Feature Detection
335
+ Detect interesting points or features in the image:
336
+ - **Harris Corner**: Detects corner points using intensity changes
337
+ - **Shi-Tomasi**: More robust corner detection
338
+ - **FAST**: High-speed corner detection
339
+
340
+ Parameters for Harris Corner:
341
+ - **Block Size**: Size of neighborhood considered
342
+ - **Kernel Size**: Aperture parameter for Sobel operator
343
+ - **k**: Harris detector free parameter
344
+ """)
345
+
346
  detector = st.sidebar.selectbox(
347
  "Select Detector",
348
  ["Harris Corner", "Shi-Tomasi", "FAST"]
 
377
  cv2.drawKeypoints(original_img, kp, processed_img, color=(0, 0, 255))
378
 
379
  elif processing_option == "Histogram Operations":
380
+ st.sidebar.markdown("""
381
+ ### Histogram Operations
382
+ Analyze and modify image intensity distribution:
383
+ - **Show Histogram**: Display color/intensity distribution
384
+ - **Equalization**: Enhance contrast using histogram equalization
385
+ - **CLAHE**: Contrast Limited Adaptive Histogram Equalization
386
+ """)
387
+
388
  operation = st.sidebar.selectbox(
389
  "Select Operation",
390
  ["Show Histogram", "Equalization", "CLAHE"]
 
410
  processed_img = apply_histogram_equalization(original_img, "CLAHE")
411
 
412
  elif processing_option == "Advanced Effects":
413
+ st.sidebar.markdown("""
414
+ ### Advanced Effects
415
+ Apply complex image transformations:
416
+ - **Pencil Sketch**: Convert image to pencil drawing style
417
+ - **Cartoon**: Create cartoon-like effect
418
+ - **HDR Effect**: Enhance local details
419
+ """)
420
+
421
  effect = st.sidebar.selectbox(
422
  "Select Effect",
423
  ["Pencil Sketch", "Cartoon", "HDR Effect"]