Update pages/4_Image Augmentation.py
Browse files- 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
|
| 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 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 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 |
-
|
| 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 |
-
|
| 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)
|