Spaces:
Sleeping
Sleeping
Update pages/Data Collection.py
Browse files- pages/Data Collection.py +43 -2
pages/Data Collection.py
CHANGED
|
@@ -747,7 +747,7 @@ elif st.session_state.current_page == "image_operations":
|
|
| 747 |
|
| 748 |
# Heading for cv2.merge() function
|
| 749 |
st.markdown("""
|
| 750 |
-
<h3 style="color: #
|
| 751 |
""", unsafe_allow_html=True)
|
| 752 |
|
| 753 |
# About cv2.merge() function
|
|
@@ -802,7 +802,7 @@ elif st.session_state.current_page == "image_operations":
|
|
| 802 |
|
| 803 |
# Heading for Splitting Channels
|
| 804 |
st.markdown("""
|
| 805 |
-
<h3 style="color: #
|
| 806 |
""", unsafe_allow_html=True)
|
| 807 |
|
| 808 |
# About cv2.split() function
|
|
@@ -845,6 +845,47 @@ elif st.session_state.current_page == "image_operations":
|
|
| 845 |
cv2.waitKey(0)
|
| 846 |
cv2.destroyAllWindows()""", language="python")
|
| 847 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 848 |
elif st.session_state.current_page == "explore_audio":
|
| 849 |
st.markdown("""
|
| 850 |
<h3 style="color: #e25822;">Exploring Audio</h3>
|
|
|
|
| 747 |
|
| 748 |
# Heading for cv2.merge() function
|
| 749 |
st.markdown("""
|
| 750 |
+
<h3 style="color: #e25822;">Merging Color Channels</h3>
|
| 751 |
""", unsafe_allow_html=True)
|
| 752 |
|
| 753 |
# About cv2.merge() function
|
|
|
|
| 802 |
|
| 803 |
# Heading for Splitting Channels
|
| 804 |
st.markdown("""
|
| 805 |
+
<h3 style="color: #e25822;">Splitting Channels</h3>
|
| 806 |
""", unsafe_allow_html=True)
|
| 807 |
|
| 808 |
# About cv2.split() function
|
|
|
|
| 845 |
cv2.waitKey(0)
|
| 846 |
cv2.destroyAllWindows()""", language="python")
|
| 847 |
|
| 848 |
+
# Allow user to upload an image
|
| 849 |
+
uploaded_file = st.file_uploader("Upload an image", type=["jpg", "png", "jpeg"])
|
| 850 |
+
|
| 851 |
+
if uploaded_file is not None:
|
| 852 |
+
# Convert the uploaded image to an OpenCV-compatible format
|
| 853 |
+
image = np.array(bytearray(uploaded_file.read()), dtype=np.uint8)
|
| 854 |
+
img = cv2.imdecode(image, 1) # Decode into an image
|
| 855 |
+
|
| 856 |
+
# Split the image into Blue, Green, and Red channels
|
| 857 |
+
b, g, r = cv2.split(img)
|
| 858 |
+
|
| 859 |
+
# Create a zeros array to hold the empty channels
|
| 860 |
+
zeros = np.zeros(img.shape[:-1], dtype=np.uint8)
|
| 861 |
+
|
| 862 |
+
# Merge the Blue channel with zeros for Green and Red
|
| 863 |
+
blue_channel = cv2.merge([b, zeros, zeros])
|
| 864 |
+
green_channel = cv2.merge([zeros, g, zeros])
|
| 865 |
+
red_channel = cv2.merge([zeros, zeros, r])
|
| 866 |
+
|
| 867 |
+
# Display the images with captions
|
| 868 |
+
st.image(blue_channel, caption="Blue Channel", channels="BGR", use_column_width=True)
|
| 869 |
+
st.image(green_channel, caption="Green Channel", channels="BGR", use_column_width=True)
|
| 870 |
+
st.image(red_channel, caption="Red Channel", channels="BGR", use_column_width=True)
|
| 871 |
+
|
| 872 |
+
# Merge the channels back together for the original image
|
| 873 |
+
original_img = cv2.merge([b, g, r])
|
| 874 |
+
|
| 875 |
+
# Display the original image
|
| 876 |
+
st.image(original_img, caption="Original Image", channels="BGR", use_column_width=True)
|
| 877 |
+
|
| 878 |
+
# Optionally, provide a download link for the processed image
|
| 879 |
+
st.download_button(
|
| 880 |
+
label="Download Merged Image",
|
| 881 |
+
data=cv2.imencode('.jpg', original_img)[1].tobytes(),
|
| 882 |
+
file_name="merged_image.jpg",
|
| 883 |
+
mime="image/jpeg"
|
| 884 |
+
)
|
| 885 |
+
else:
|
| 886 |
+
st.write("Please upload an image to proceed.")
|
| 887 |
+
|
| 888 |
+
|
| 889 |
elif st.session_state.current_page == "explore_audio":
|
| 890 |
st.markdown("""
|
| 891 |
<h3 style="color: #e25822;">Exploring Audio</h3>
|