This Image Analysis Tool is an interactive Python-based application designed to analyze uploaded images. It provides insights such as image dimensions, color channel distribution, pixel intensity, and edge detection. The tool also includes visualizations like histograms and edge maps, making it an excellent choice for educational and prototyping purposes. The project runs seamlessly in Google Colab.
- Interactive widget for uploading images directly in Google Colab.
- Accepts common image formats such as PNG, JPG, and JPEG.
- Dimensions: Displays the height and width of the image.
- Number of Color Channels: Identifies the channels (e.g., RGB has 3 channels).
- Total Pixels: Calculates the total number of pixels in the image.
- Plots the pixel intensity distribution for Red, Green, and Blue channels.
- Converts the image to grayscale and calculates the average pixel intensity.
- Uses the Canny Edge Detection algorithm to highlight edges in the image.
- Visualizes edges with a grayscale edge map.
Run the following command to install the required Python libraries:
!pip install opencv-python-headless matplotlib pillow
Copy the script into a Google Colab notebook.
-
Run the Code:
- Paste the code into a Google Colab notebook and run it.
-
Upload an Image:
- Use the interactive widget to upload an image file.
-
Analyze the Image:
- The tool will automatically display the uploaded image, analyze its properties, and generate visualizations.
-
View Results:
- Results are displayed in the notebook, including image properties, histograms, and edge detection output.
The upload_image
function uses an interactive widget to allow users to upload images:
upload_widget = widgets.FileUpload(accept='image/*', multiple=False)
The display_image
function renders the uploaded image:
plt.imshow(image)
plt.axis('off')
plt.title("Uploaded Image")
The analyze_image
function calculates and prints:
- Dimensions (
image.shape[0]
for height,image.shape[1]
for width). - Number of color channels (
image.shape[2]
). - Total pixels (
image.size
).
A histogram is plotted for each color channel (Red, Green, Blue):
hist = cv2.calcHist([image], [i], None, [256], [0, 256])
plt.plot(hist, color=color.lower(), label=f"{color} Channel")
The image is converted to grayscale, and the average intensity is calculated:
gray_image = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)
avg_intensity = np.mean(gray_image)
The Canny Edge Detection algorithm highlights edges in the image:
edges = cv2.Canny(gray_image, 100, 200)
plt.imshow(edges, cmap='gray')
plt.title("Edge Detection (Canny)")
An uploaded image (e.g., example.jpg
).
-
Image Properties:
📏 Image Dimensions: 512x512 (Height x Width) 📊 Number of Color Channels: 3 🖼️ Total Pixels: 786,432
-
Color Histogram:
- A chart showing the pixel intensity distribution for Red, Green, and Blue channels.
-
Grayscale Analysis:
🔅 Average Intensity (Grayscale): 120.45
-
Edge Detection:
- A grayscale edge map highlighting the edges in the image.
- Demonstrates key image processing techniques such as histograms and edge detection.
- Serves as a quick prototype for image analysis workflows.
- Helps users understand the properties and structure of digital images.
-
Advanced Filters:
- Add options for image blurring, sharpening, and thresholding.
-
ROI Analysis:
- Allow users to select and analyze specific regions of the image.
-
Batch Analysis:
- Support the analysis of multiple images at once.
-
Feature Detection:
- Add functionality for detecting shapes, objects, or faces.
-
Image Comparison:
- Enable comparison of two images side-by-side for differences or similarities.
Contributions are welcome! Here's how you can contribute:
- Fork the repository.
- Create a new branch:
git checkout -b feature-name
- Commit your changes:
git commit -m "Add feature: feature-name"
- Push your branch:
git push origin feature-name
- Open a pull request.
If you find this project helpful:
- ⭐ Star the repository on GitHub.
- 🗣️ Share it with others.
Let me know if you'd like further refinements or additional sections! 🚀