sree4411 commited on
Commit
507758e
·
verified ·
1 Parent(s): 28402f2

Update pages/4_Image Augmentation.py

Browse files
Files changed (1) hide show
  1. pages/4_Image Augmentation.py +14 -20
pages/4_Image Augmentation.py CHANGED
@@ -4,7 +4,7 @@ import numpy as np
4
  import cv2
5
  import random
6
  import io
7
- import cv2
8
 
9
  st.title("Interactive Image Augmentation with Streamlit")
10
 
@@ -14,23 +14,22 @@ st.write("""
14
  Image augmentation refers to a set of techniques used to increase the diversity of training images available for a machine learning model without actually collecting new images. It's commonly used in computer vision tasks to improve the performance of models by making them more robust to variations in the data.
15
 
16
  ### Common Types of Image Augmentation:
17
- 1. **Flipping**: Horizontally or vertically flipping an image.
18
- 2. **Rotation**: Rotating the image by a certain angle.
19
- 3. **Scaling**: Zooming in or out on the image.
20
- 4. **Translation**: Shifting the image in the x or y direction.
21
- 5. **Shearing**: Distorting the image along one axis.
22
- 6. **Color Jittering**: Randomly changing the brightness, contrast, saturation, and hue of the image.
23
- 7. **Noise Addition**: Adding random noise to the image to simulate variations.
24
- 8. **Cropping**: Randomly cropping a portion of the image.
25
- 9. **Blurring**: Applying different types of blurs (e.g., Gaussian blur).
26
- 10. **Affine Transformations**: Applying geometric transformations like scaling, rotation, and translation together.
27
- 11. **Elastic Transformations**: Randomly deforming the image using displacement fields.
28
- 12. **Cutout**: Randomly masking out a section of the image.
29
  """)
30
 
31
  # Function to convert numpy array to image and provide download link
32
  def get_image_download_link(img_array, filename, text):
33
  img = Image.fromarray(img_array)
 
34
  buffered = io.BytesIO()
35
  img.save(buffered, format="JPEG")
36
  buffered.seek(0)
@@ -57,7 +56,7 @@ if uploaded_file is not None:
57
  translate = st.checkbox("Translate")
58
  shear = st.checkbox("Shear")
59
  color_jitter = st.checkbox("Color Jittering")
60
- add_noise = st.checkbox("Add Noise")
61
 
62
  if flip_horizontally:
63
  img_array = cv2.flip(img_array, 1)
@@ -95,12 +94,7 @@ if uploaded_file is not None:
95
  img_array = cv2.convertScaleAbs(img_array, alpha=contrast, beta=brightness * 127)
96
  st.markdown(get_image_download_link(img_array, "color_jittered.jpg", "Download Color Jittered Image"), unsafe_allow_html=True)
97
 
98
- if add_noise:
99
- noise = np.random.randn(*img_array.shape) * 10
100
- img_array = img_array + noise
101
- img_array = np.clip(img_array, 0, 255).astype(np.uint8)
102
- st.markdown(get_image_download_link(img_array, "noisy.jpg", "Download Noisy Image"), unsafe_allow_html=True)
103
-
104
  # Convert numpy array back to image
105
  augmented_image = Image.fromarray(img_array)
106
  st.image(augmented_image, caption='Augmented Image.', use_column_width=True)
 
4
  import cv2
5
  import random
6
  import io
7
+ import base64
8
 
9
  st.title("Interactive Image Augmentation with Streamlit")
10
 
 
14
  Image augmentation refers to a set of techniques used to increase the diversity of training images available for a machine learning model without actually collecting new images. It's commonly used in computer vision tasks to improve the performance of models by making them more robust to variations in the data.
15
 
16
  ### Common Types of Image Augmentation:
17
+ **Flipping**: Horizontally or vertically flipping an image.
18
+ **Rotation**: Rotating the image by a certain angle.
19
+ **Scaling**: Zooming in or out on the image.
20
+ **Translation**: Shifting the image in the x or y direction.
21
+ **Shearing**: Distorting the image along one axis.
22
+ **Color Jittering**: Randomly changing the brightness, contrast, saturation, and hue of the image.
23
+ **Cropping**: Randomly cropping a portion of the image.
24
+ **Blurring**: Applying different types of blurs (e.g., Gaussian blur).
25
+ **Affine Transformations**: Applying geometric transformations like scaling, rotation, and translation together.
26
+ **Cutout**: Randomly masking out a section of the image.
 
 
27
  """)
28
 
29
  # Function to convert numpy array to image and provide download link
30
  def get_image_download_link(img_array, filename, text):
31
  img = Image.fromarray(img_array)
32
+ img = img.convert("RGB") # Convert to RGB mode
33
  buffered = io.BytesIO()
34
  img.save(buffered, format="JPEG")
35
  buffered.seek(0)
 
56
  translate = st.checkbox("Translate")
57
  shear = st.checkbox("Shear")
58
  color_jitter = st.checkbox("Color Jittering")
59
+
60
 
61
  if flip_horizontally:
62
  img_array = cv2.flip(img_array, 1)
 
94
  img_array = cv2.convertScaleAbs(img_array, alpha=contrast, beta=brightness * 127)
95
  st.markdown(get_image_download_link(img_array, "color_jittered.jpg", "Download Color Jittered Image"), unsafe_allow_html=True)
96
 
97
+
 
 
 
 
 
98
  # Convert numpy array back to image
99
  augmented_image = Image.fromarray(img_array)
100
  st.image(augmented_image, caption='Augmented Image.', use_column_width=True)