Spaces:
Build error
Build error
Update pages/Roadmap of ML Project.py
Browse files- pages/Roadmap of ML Project.py +0 -135
pages/Roadmap of ML Project.py
CHANGED
|
@@ -495,141 +495,6 @@ elif st.session_state.step == "data_collection":
|
|
| 495 |
notebook_html = f.read()
|
| 496 |
st.components.v1.html(notebook_html, height=500, scrolling=True)
|
| 497 |
|
| 498 |
-
image_augumentation_button= st.button('Image Augumentation')
|
| 499 |
-
if image_augumentation_button:
|
| 500 |
-
# Streamlit header
|
| 501 |
-
st.markdown('<h1><center>Affine Transformatiosn on Image</center></h1>', unsafe_allow_html=True)
|
| 502 |
-
st.write("""Affine transformations are used in image augmentation to manipulate and alter images by applying operations such as translation, rotation, scaling, and shearing.
|
| 503 |
-
These transformations help to generate new images from the existing ones, thereby increasing the dataset diversity.""")
|
| 504 |
-
# Image augmentation functions
|
| 505 |
-
def rotate_image(image, angle):
|
| 506 |
-
(h, w) = image.shape[:2] # Get image dimensions
|
| 507 |
-
center = (w // 2, h // 2) # Define the center of the image
|
| 508 |
-
M = cv2.getRotationMatrix2D(center, angle, 1.0) # Rotation matrix
|
| 509 |
-
rotated = cv2.warpAffine(image, M, (w, h),borderMode=cv2.BORDER_REFLECT) # Apply rotation
|
| 510 |
-
return rotated
|
| 511 |
-
|
| 512 |
-
def shifting(image, tx, ty):
|
| 513 |
-
t_matrix = np.array([[1, 0, tx],
|
| 514 |
-
[0, 1, ty]], dtype=np.float32)
|
| 515 |
-
t_img = cv2.warpAffine(image, t_matrix, (image.shape[1], image.shape[0])) # Adjust size to original
|
| 516 |
-
return t_img
|
| 517 |
-
|
| 518 |
-
def scaling(image,fx,fy):
|
| 519 |
-
scaled_image=cv2.resize(image,None,fx=fx, fy=fy)
|
| 520 |
-
return scaled_image
|
| 521 |
-
|
| 522 |
-
def shearing(image,shx,shy,tsx,tsy):
|
| 523 |
-
shearing_matrix = np.array([[1,shx,tsx],[shy,1,tsy]],dtype= np.float32)
|
| 524 |
-
sheared_image=cv2.warpAffine(image,shearing_matrix,(image.shape[1], image.shape[0]))
|
| 525 |
-
return sheared_image
|
| 526 |
-
|
| 527 |
-
def cropping(image,x1,x2,y1,y2):
|
| 528 |
-
cropped_image=image[x1:x2,y1:y2]
|
| 529 |
-
return cropped_image
|
| 530 |
-
|
| 531 |
-
|
| 532 |
-
|
| 533 |
-
# Streamlit app
|
| 534 |
-
st.markdown("<b>Upload an image and apply various augmentation techniques.</b>", unsafe_allow_html=True)
|
| 535 |
-
|
| 536 |
-
# File uploader for images
|
| 537 |
-
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "png", "jpeg"])
|
| 538 |
-
|
| 539 |
-
if uploaded_file is not None:
|
| 540 |
-
# Read the image using OpenCV directly (ensure it's in BGR format)
|
| 541 |
-
image_bgr = np.asarray(bytearray(uploaded_file.read()), dtype=np.uint8)
|
| 542 |
-
image_bgr = cv2.imdecode(image_bgr, cv2.IMREAD_COLOR) # Read as BGR image
|
| 543 |
-
|
| 544 |
-
# Display the uploaded image (converted to RGB for Streamlit)
|
| 545 |
-
image_rgb = cv2.cvtColor(image_bgr, cv2.COLOR_BGR2RGB) # Convert to RGB for display
|
| 546 |
-
st.image(image_rgb, caption="Uploaded Image", use_container_width=True)
|
| 547 |
-
|
| 548 |
-
st.subheader('Rotation')
|
| 549 |
-
|
| 550 |
-
# Rotation slider
|
| 551 |
-
rotate = st.slider("Rotate Angle", 0, 180, 45)
|
| 552 |
-
|
| 553 |
-
# Apply rotation based on the slider value
|
| 554 |
-
if rotate != 0:
|
| 555 |
-
# Apply rotation
|
| 556 |
-
rotated_image_bgr = rotate_image(image_bgr, rotate)
|
| 557 |
-
|
| 558 |
-
# Convert back to RGB for Streamlit
|
| 559 |
-
rotated_image_rgb = cv2.cvtColor(rotated_image_bgr, cv2.COLOR_BGR2RGB)
|
| 560 |
-
|
| 561 |
-
# Display the rotated image
|
| 562 |
-
st.image(rotated_image_rgb, caption=f"Rotated Image ({rotate}°)", use_container_width=True)
|
| 563 |
-
else:
|
| 564 |
-
st.write("No rotation applied.")
|
| 565 |
-
|
| 566 |
-
st.subheader('Translation')
|
| 567 |
-
# Shifting sliders
|
| 568 |
-
Tx = st.slider('tx distance', -100, 100, 0) # Allow both positive and negative values
|
| 569 |
-
Ty = st.slider('ty distance', -100, 100, 0)
|
| 570 |
-
|
| 571 |
-
# Apply shifting based on the sliders
|
| 572 |
-
if Tx != 0 or Ty != 0:
|
| 573 |
-
shifted_image = shifting(image_bgr, Tx, Ty)
|
| 574 |
-
shifted_image_rgb = cv2.cvtColor(shifted_image, cv2.COLOR_BGR2RGB)
|
| 575 |
-
st.image(shifted_image_rgb, caption=f"Translated Image (Tx: {Tx}, Ty: {Ty})", use_container_width=True)
|
| 576 |
-
else:
|
| 577 |
-
st.write("No Translation applied.")
|
| 578 |
-
|
| 579 |
-
st.subheader('Scaling')
|
| 580 |
-
|
| 581 |
-
#scaling
|
| 582 |
-
fx=st.slider('fx distance', 0.5,1.5, 0.0,)
|
| 583 |
-
fy=st.slider('fy distance', 0.5, 1.5, 0.0)
|
| 584 |
-
# apply scaling based on sliders
|
| 585 |
-
if fx!=0 or fy!=0:
|
| 586 |
-
scaling_image = scaling(image_bgr,fx,fy)
|
| 587 |
-
scaling_image_rgb=cv2.cvtColor(scaling_image, cv2.COLOR_BGR2RGB)
|
| 588 |
-
st.image(scaling_image_rgb, caption=f'Scaled Image (fx:{fx},fy:{fy})',use_container_width=True)
|
| 589 |
-
else:
|
| 590 |
-
st.write('No scaling Applied')
|
| 591 |
-
|
| 592 |
-
|
| 593 |
-
st.subheader('Shearing')
|
| 594 |
-
|
| 595 |
-
# Shearing sliders
|
| 596 |
-
shx = st.slider('Shearing on x-axis', 0.0, 3.0, 0.0, key='slider_shx')
|
| 597 |
-
shy = st.slider('Shearing on y-axis', 0.0, 3.0, 0.0, key='slider_shy')
|
| 598 |
-
tsx = st.slider('Translation on x-axis (tx)', -100, 100, 0, key='slider_tsx')
|
| 599 |
-
tsy = st.slider('Translation on y-axis (ty)', -100, 100, 0, key='slider_tsy')
|
| 600 |
-
|
| 601 |
-
# Apply shearing on the image
|
| 602 |
-
if shx != 0 or shy != 0:
|
| 603 |
-
# Assuming 'shearing' is a function that applies the shear transformation
|
| 604 |
-
shearing_image = shearing(image_bgr, shx, shy, tsx, tsy)
|
| 605 |
-
|
| 606 |
-
# Convert the sheared image to RGB for display in Streamlit
|
| 607 |
-
shearing_image_rgb = cv2.cvtColor(shearing_image, cv2.COLOR_BGR2RGB)
|
| 608 |
-
|
| 609 |
-
# Display the sheared image
|
| 610 |
-
st.image(
|
| 611 |
-
shearing_image_rgb,
|
| 612 |
-
caption=f'Sheared image (sx: {shx}, sy: {shy})',
|
| 613 |
-
use_container_width=True
|
| 614 |
-
)
|
| 615 |
-
else:
|
| 616 |
-
st.write("No Shearing applied.")
|
| 617 |
-
|
| 618 |
-
st.subheader('Cropping')
|
| 619 |
-
|
| 620 |
-
# Cropping sliders
|
| 621 |
-
x1 = st.slider('x1 value', 0, 1000, 0, key='slider_x1')
|
| 622 |
-
x2 = st.slider('x2 value', 0, 1000, 0, key='slider_x2')
|
| 623 |
-
y1 = st.slider('y1 value', 0, 1000, 0, key='slider_y1')
|
| 624 |
-
y2 = st.slider('y2 value', 0, 1000, 0, key='slider_y2')
|
| 625 |
-
|
| 626 |
-
if x1 != 0 or x2 != 0 or y1 != 0 or y2 != 0:
|
| 627 |
-
cropping_image = cropping(image_bgr, x1, x2, y1, y2)
|
| 628 |
-
cropping_img_rgb = cv2.cvtColor(cropping_image, cv2.COLOR_BGR2RGB)
|
| 629 |
-
# Display the cropped image with proper caption formatting
|
| 630 |
-
st.image(cropping_img_rgb, caption=f'cropped image, image[{x1}:{x2}, {y1}:{y2}]', use_container_width=True)
|
| 631 |
-
else:
|
| 632 |
-
st.write('No Cropping Applied')
|
| 633 |
|
| 634 |
|
| 635 |
Video_button= st.button("Videos")
|
|
|
|
| 495 |
notebook_html = f.read()
|
| 496 |
st.components.v1.html(notebook_html, height=500, scrolling=True)
|
| 497 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 498 |
|
| 499 |
|
| 500 |
Video_button= st.button("Videos")
|