ronakreddy18 commited on
Commit
a874bbb
·
verified ·
1 Parent(s): 4c43f1c

Update pages/LIFE_CYCLE_OF_MACHINE_LEARNING.py

Browse files
pages/LIFE_CYCLE_OF_MACHINE_LEARNING.py CHANGED
@@ -329,6 +329,158 @@ def operations_using_opencv_page():
329
  if st.button("Back to Data Collection"):
330
  st.session_state.page = "data_collection"
331
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
332
 
333
 
334
 
@@ -418,6 +570,9 @@ def main():
418
  introduction_to_image_page()
419
  elif page == "operations_using_opencv":
420
  operations_using_opencv_page()
421
-
 
 
 
422
  if __name__ == "__main__":
423
  main()
 
329
  if st.button("Back to Data Collection"):
330
  st.session_state.page = "data_collection"
331
 
332
+ ##------------CONVERSION OF IMAGE-----------------
333
+ import streamlit as st
334
+
335
+ def Conversion_of_Images_page():
336
+ # Header for Image Conversion
337
+ st.header("🔄 Converting Images Between Different Color Spaces")
338
+
339
+ st.markdown("""
340
+ **OpenCV supports many color spaces for image processing.**
341
+
342
+ **Common Conversions:**
343
+
344
+ - **BGR to Grayscale:** Converts a color image to grayscale.
345
+ - **BGR to RGB:** Converts from OpenCV's default BGR format to the standard RGB format.
346
+ - **BGR to HSV:** Converts the image to the HSV (Hue, Saturation, Value) color space.
347
+
348
+ **Examples of Conversions:**
349
+
350
+ ```python
351
+ import cv2
352
+
353
+ # Load the image
354
+ image = cv2.imread('image.jpg')
355
+
356
+ # Convert BGR to Grayscale
357
+ gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
358
+
359
+ # Convert BGR to RGB
360
+ rgb_image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
361
+
362
+ # Convert BGR to HSV
363
+ hsv_image = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
364
+ ```
365
+
366
+ **Why Convert Color Spaces?**
367
+ - **Grayscale:** Useful for reducing image complexity in tasks like edge detection.
368
+ - **RGB:** Standard format for visualization in libraries like `matplotlib`.
369
+ - **HSV:** Useful for color-based segmentation, as it separates color information from brightness.
370
+ """)
371
+
372
+ # Header for Splitting Channels
373
+ st.header("🔹 Splitting Color Channels in an Image")
374
+
375
+ st.markdown("""
376
+ **Splitting an image into its individual color channels (B, G, R) allows you to analyze or modify each channel independently.**
377
+
378
+ **Syntax:**
379
+ ```python
380
+ b, g, r = cv2.split(image)
381
+ ```
382
+
383
+ **Example:**
384
+ ```python
385
+ import cv2
386
+
387
+ # Load the image
388
+ image = cv2.imread('image.jpg')
389
+
390
+ # Split the image into Blue, Green, and Red channels
391
+ blue_channel, green_channel, red_channel = cv2.split(image)
392
+
393
+ # Display the channels separately (Optional)
394
+ cv2.imshow('Blue Channel', blue_channel)
395
+ cv2.imshow('Green Channel', green_channel)
396
+ cv2.imshow('Red Channel', red_channel)
397
+ cv2.waitKey(0)
398
+ cv2.destroyAllWindows()
399
+ ```
400
+
401
+ **Explanation:**
402
+ - The `cv2.split()` function returns the Blue, Green, and Red channels as separate images (grayscale format).
403
+ """)
404
+
405
+ # Header for Merging Channels
406
+ st.header("🔹 Merging Color Channels in an Image")
407
+
408
+ st.markdown("""
409
+ **You can merge the individual channels back into a color image using `cv2.merge()`.**
410
+
411
+ **Syntax:**
412
+ ```python
413
+ merged_image = cv2.merge((b, g, r))
414
+ ```
415
+
416
+ **Example:**
417
+ ```python
418
+ import cv2
419
+
420
+ # Load the image
421
+ image = cv2.imread('image.jpg')
422
+
423
+ # Split the image into channels
424
+ b, g, r = cv2.split(image)
425
+
426
+ # Merge the channels back into a color image
427
+ merged_image = cv2.merge((b, g, r))
428
+
429
+ # Display the merged image
430
+ cv2.imshow('Merged Image', merged_image)
431
+ cv2.waitKey(0)
432
+ cv2.destroyAllWindows()
433
+ ```
434
+
435
+ **Explanation:**
436
+ - The `cv2.merge()` function takes a tuple of channels `(b, g, r)` and combines them back into a single color image.
437
+ - You can manipulate the individual channels before merging to achieve different effects.
438
+ """)
439
+
440
+ # Header for Combining with Modifications
441
+ st.header("🎨 Modifying Channels Before Merging")
442
+
443
+ st.markdown("""
444
+ **You can modify each channel (e.g., increase brightness in the red channel) before merging them back together.**
445
+
446
+ **Example:**
447
+ ```python
448
+ import cv2
449
+
450
+ # Load the image
451
+ image = cv2.imread('image.jpg')
452
+
453
+ # Split channels
454
+ b, g, r = cv2.split(image)
455
+
456
+ # Increase the intensity of the red channel
457
+ r = cv2.add(r, 50)
458
+
459
+ # Merge the modified channels
460
+ modified_image = cv2.merge((b, g, r))
461
+
462
+ # Display the modified image
463
+ cv2.imshow('Modified Image', modified_image)
464
+ cv2.waitKey(0)
465
+ cv2.destroyAllWindows()
466
+ ```
467
+
468
+ **Explanation:**
469
+ - In this example, `cv2.add(r, 50)` increases the intensity of the red channel by 50.
470
+ - After modification, the channels are merged back to create the final image.
471
+ """)
472
+
473
+
474
+ # Navigation Button
475
+ if st.button("Video capture and explanation of cv2.waitKey"):
476
+ st.session_state.page = "Video capture and explanation of cv2.waitKey"
477
+
478
+ # Navigation Button
479
+ if st.button("Back to Data Collection"):
480
+ st.session_state.page = "data_collection"
481
+
482
+
483
+
484
 
485
 
486
 
 
570
  introduction_to_image_page()
571
  elif page == "operations_using_opencv":
572
  operations_using_opencv_page()
573
+ elif page == "Conversion_of_Images_page"
574
+ Conversion_of_Images_page()
575
+ elif page == "video_capture_cv2.waitKey()_page"
576
+ video_capture_cv2.waitKey()_page
577
  if __name__ == "__main__":
578
  main()