Update pages/Life_cycle_of_ML.py
Browse files- pages/Life_cycle_of_ML.py +57 -0
pages/Life_cycle_of_ML.py
CHANGED
|
@@ -456,11 +456,35 @@ def More():
|
|
| 456 |
# Title
|
| 457 |
st.title("Image Processing Using OpenCV")
|
| 458 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 459 |
# Upload an Image
|
| 460 |
uploaded_file = st.file_uploader("Upload an Image (JPG/PNG):", type=["jpg", "png"])
|
| 461 |
|
| 462 |
if uploaded_file:
|
| 463 |
# Read the uploaded image
|
|
|
|
|
|
|
|
|
|
|
|
|
| 464 |
file_bytes = np.asarray(bytearray(uploaded_file.read()), dtype=np.uint8)
|
| 465 |
image = cv2.imdecode(file_bytes, cv2.IMREAD_COLOR)
|
| 466 |
|
|
@@ -469,6 +493,11 @@ def More():
|
|
| 469 |
st.write("An image is a grid of pixels. Each pixel holds color or intensity information. Here's your image!")
|
| 470 |
st.image(cv2.cvtColor(image, cv2.COLOR_BGR2RGB), caption="Original Image", use_column_width=True)
|
| 471 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 472 |
# Convert to Grayscale
|
| 473 |
st.subheader("2. What is Meant by Color Spaces?")
|
| 474 |
st.write(
|
|
@@ -477,10 +506,24 @@ def More():
|
|
| 477 |
grayscale_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
|
| 478 |
hsv_image = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
|
| 479 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 480 |
# Display color space conversions
|
| 481 |
st.image(grayscale_image, caption="Grayscale Image", use_column_width=True, channels="GRAY")
|
| 482 |
st.image(cv2.cvtColor(hsv_image, cv2.COLOR_HSV2RGB), caption="HSV Image", use_column_width=True)
|
| 483 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 484 |
# Split and Merge Channels
|
| 485 |
st.subheader("3. Color Space Techniques")
|
| 486 |
st.write(
|
|
@@ -489,12 +532,26 @@ def More():
|
|
| 489 |
b, g, r = cv2.split(image)
|
| 490 |
merged_image = cv2.merge((r, g, b))
|
| 491 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 492 |
# Display each channel and the manipulated image
|
| 493 |
st.image(b, caption="Blue Channel", use_column_width=True, channels="GRAY")
|
| 494 |
st.image(g, caption="Green Channel", use_column_width=True, channels="GRAY")
|
| 495 |
st.image(r, caption="Red Channel", use_column_width=True, channels="GRAY")
|
| 496 |
st.image(cv2.cvtColor(merged_image, cv2.COLOR_BGR2RGB), caption="Manipulated Image (Swapped Channels)", use_column_width=True)
|
| 497 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 498 |
st.write("These operations help in extracting and analyzing features from images!")
|
| 499 |
|
| 500 |
else:
|
|
|
|
| 456 |
# Title
|
| 457 |
st.title("Image Processing Using OpenCV")
|
| 458 |
|
| 459 |
+
# Introduction
|
| 460 |
+
st.write("""
|
| 461 |
+
### Understanding Image Processing Concepts
|
| 462 |
+
1. **What is an Image?**
|
| 463 |
+
- An image is a digital representation of visual data stored as a grid of pixels. Each pixel contains color information, represented in formats like grayscale or RGB.
|
| 464 |
+
- In machine learning, images are processed to extract meaningful features for tasks like object detection, recognition, and classification.
|
| 465 |
+
|
| 466 |
+
2. **What is Meant by Color Spaces?**
|
| 467 |
+
- Color spaces define the range and representation of colors in images. Common color spaces include:
|
| 468 |
+
- **RGB** (Red, Green, Blue): Used for displaying images on screens.
|
| 469 |
+
- **HSV** (Hue, Saturation, Value): Helpful for color segmentation.
|
| 470 |
+
- **Grayscale**: Simplified representation with intensity levels.
|
| 471 |
+
|
| 472 |
+
3. **Color Space Techniques**
|
| 473 |
+
- Techniques for working with color spaces include:
|
| 474 |
+
- **Converting between color spaces** for better feature extraction.
|
| 475 |
+
- **Color channel manipulation** to enhance certain features.
|
| 476 |
+
- **Thresholding and segmentation** for isolating specific objects based on color.
|
| 477 |
+
""")
|
| 478 |
+
|
| 479 |
# Upload an Image
|
| 480 |
uploaded_file = st.file_uploader("Upload an Image (JPG/PNG):", type=["jpg", "png"])
|
| 481 |
|
| 482 |
if uploaded_file:
|
| 483 |
# Read the uploaded image
|
| 484 |
+
st.code("""
|
| 485 |
+
file_bytes = np.asarray(bytearray(uploaded_file.read()), dtype=np.uint8)
|
| 486 |
+
image = cv2.imdecode(file_bytes, cv2.IMREAD_COLOR)
|
| 487 |
+
""", language="python")
|
| 488 |
file_bytes = np.asarray(bytearray(uploaded_file.read()), dtype=np.uint8)
|
| 489 |
image = cv2.imdecode(file_bytes, cv2.IMREAD_COLOR)
|
| 490 |
|
|
|
|
| 493 |
st.write("An image is a grid of pixels. Each pixel holds color or intensity information. Here's your image!")
|
| 494 |
st.image(cv2.cvtColor(image, cv2.COLOR_BGR2RGB), caption="Original Image", use_column_width=True)
|
| 495 |
|
| 496 |
+
st.code("""
|
| 497 |
+
# Display the image
|
| 498 |
+
st.image(cv2.cvtColor(image, cv2.COLOR_BGR2RGB), caption="Original Image", use_column_width=True)
|
| 499 |
+
""", language="python")
|
| 500 |
+
|
| 501 |
# Convert to Grayscale
|
| 502 |
st.subheader("2. What is Meant by Color Spaces?")
|
| 503 |
st.write(
|
|
|
|
| 506 |
grayscale_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
|
| 507 |
hsv_image = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
|
| 508 |
|
| 509 |
+
st.code("""
|
| 510 |
+
# Convert to Grayscale
|
| 511 |
+
grayscale_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
|
| 512 |
+
|
| 513 |
+
# Convert to HSV
|
| 514 |
+
hsv_image = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
|
| 515 |
+
""", language="python")
|
| 516 |
+
|
| 517 |
# Display color space conversions
|
| 518 |
st.image(grayscale_image, caption="Grayscale Image", use_column_width=True, channels="GRAY")
|
| 519 |
st.image(cv2.cvtColor(hsv_image, cv2.COLOR_HSV2RGB), caption="HSV Image", use_column_width=True)
|
| 520 |
|
| 521 |
+
st.code("""
|
| 522 |
+
# Display Grayscale and HSV Images
|
| 523 |
+
st.image(grayscale_image, caption="Grayscale Image", use_column_width=True, channels="GRAY")
|
| 524 |
+
st.image(cv2.cvtColor(hsv_image, cv2.COLOR_HSV2RGB), caption="HSV Image", use_column_width=True)
|
| 525 |
+
""", language="python")
|
| 526 |
+
|
| 527 |
# Split and Merge Channels
|
| 528 |
st.subheader("3. Color Space Techniques")
|
| 529 |
st.write(
|
|
|
|
| 532 |
b, g, r = cv2.split(image)
|
| 533 |
merged_image = cv2.merge((r, g, b))
|
| 534 |
|
| 535 |
+
st.code("""
|
| 536 |
+
# Split and Merge Channels
|
| 537 |
+
b, g, r = cv2.split(image)
|
| 538 |
+
merged_image = cv2.merge((r, g, b))
|
| 539 |
+
""", language="python")
|
| 540 |
+
|
| 541 |
# Display each channel and the manipulated image
|
| 542 |
st.image(b, caption="Blue Channel", use_column_width=True, channels="GRAY")
|
| 543 |
st.image(g, caption="Green Channel", use_column_width=True, channels="GRAY")
|
| 544 |
st.image(r, caption="Red Channel", use_column_width=True, channels="GRAY")
|
| 545 |
st.image(cv2.cvtColor(merged_image, cv2.COLOR_BGR2RGB), caption="Manipulated Image (Swapped Channels)", use_column_width=True)
|
| 546 |
|
| 547 |
+
st.code("""
|
| 548 |
+
# Display individual channels and manipulated image
|
| 549 |
+
st.image(b, caption="Blue Channel", use_column_width=True, channels="GRAY")
|
| 550 |
+
st.image(g, caption="Green Channel", use_column_width=True, channels="GRAY")
|
| 551 |
+
st.image(r, caption="Red Channel", use_column_width=True, channels="GRAY")
|
| 552 |
+
st.image(cv2.cvtColor(merged_image, cv2.COLOR_BGR2RGB), caption="Manipulated Image (Swapped Channels)", use_column_width=True)
|
| 553 |
+
""", language="python")
|
| 554 |
+
|
| 555 |
st.write("These operations help in extracting and analyzing features from images!")
|
| 556 |
|
| 557 |
else:
|