Online Scikit-Image Compiler

Code, compile, and run Scikit-Image programs online

Python
# Basic image processing using Scikit-Image

from skimage import io, color, filters
import requests
import matplotlib.pyplot as plt
from PIL import Image
from io import BytesIO
import numpy as np

# Fetch the image from the URL using requests
url = 'https://images.unsplash.com/photo-1444464666168-49d633b86797?w=800&auto=format&fit=crop&q=60&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxzZWFyY2h8MXx8YmlyZHxlbnwwfHwwfHx8Mg%3D%3D'
response = requests.get(url)
image = Image.open(BytesIO(response.content))

# Convert the image to a NumPy array
image_np = np.array(image)

# Convert the image to grayscale
gray_image = color.rgb2gray(image_np)

# Apply a Gaussian filter to the image
blurred_image = filters.gaussian(gray_image, sigma=1)

# Detect edges using the Sobel filter
edges = filters.sobel(blurred_image)

# Display the original and processed images
plt.figure(figsize=(10, 7))

plt.subplot(2, 2, 1)
plt.title('Original Image')
plt.imshow(image_np)
plt.axis('off')

plt.subplot(2, 2, 2)
plt.title('Grayscale Image')
plt.imshow(gray_image, cmap='gray')
plt.axis('off')

plt.subplot(2, 2, 3)
plt.title('Blurred Image')
plt.imshow(blurred_image, cmap='gray')
plt.axis('off')

plt.subplot(2, 2, 4)
plt.title('Edge Detection')
plt.imshow(edges, cmap='gray')
plt.axis('off')

plt.tight_layout()
plt.show()
AI Prompt