Spaces:
Sleeping
Sleeping
Update pages/video.py
Browse files57 unmodified lines58596057 unmodified linesimg = cv2.imread("path/to/image")gray_img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY""",unsafe_allow_html=True)57 unmodified lines58596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813957 unmodified linesimg = cv2.imread("path/to/image")gray_img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY""",unsafe_allow_html=True)from PIL import Image# Set the title of the app# Function to generate Black & White and Grayscale Imagesdef generate_bw_and_grayscale():# Create Black & White binary imagebw_image = np.array([[0, 1, 0, 1],[1, 0, 1, 0],[0, 1, 0, 1],[1, 0, 1, 0]])# Create Grayscale imagegrayscale_image = np.array([[0, 64, 128, 255],[255, 128, 64, 0],[0, 64, 128, 255],[255, 128, 64, 0]])# Plot and save the Black & White and Grayscale imagesfig, axes = plt.subplots(1, 2, figsize=(10, 5))# Black & Whiteaxes[0].imshow(bw_image, cmap='binary', interpolation='nearest')axes[0].set_title("Black & White Image")axes[0].axis('off')# Grayscaleaxes[1].imshow(grayscale_image, cmap='gray', interpolation='nearest')axes[1].set_title("Grayscale Image")axes[1].axis('off')plt.tight_layout()return fig# Function to generate RGB Color Space Imagesdef generate_rgb_color_space():# Create RGB arraysred = np.zeros((4, 4, 3), dtype=int)green = np.zeros((4, 4, 3), dtype=int)blue = np.zeros((4, 4, 3), dtype=int)# Add intensity to respective channelsred[:, :, 0] = 255 # Red channelgreen[:, :, 1] = 255 # Green channelblue[:, :, 2] = 255 # Blue channel# Plot RGB componentsfig, axes = plt.subplots(1, 3, figsize=(15, 5))# Redaxes[0].imshow(red)axes[0].set_title("Red Component")axes[0].axis('off')# Greenaxes[1].imshow(green)axes[1].set_title("Green Component")axes[1].axis('off')# Blueaxes[2].imshow(blue)axes[2].set_title("Blue Component")axes[2].axis('off')plt.tight_layout()return fig# Generate Black & White and Grayscale Imagesst.subheader("Black & White and Grayscale Images")bw_grayscale_fig = generate_bw_and_grayscale()st.pyplot(bw_grayscale_fig)# Generate RGB Color Space Imagesst.subheader("RGB Color Space Visualization")rgb_fig = generate_rgb_color_space()st.pyplot(rgb_fig)
pages/video.py+79