Okay, so let me tell you about my weekend project, which I’m calling “nia jaxx” for now – don’t ask, it’s a placeholder! I basically wanted to mess around with some image manipulation stuff and see what I could whip up. Here’s the lowdown.
Setting Up Shop
First things first, I needed to get my environment sorted. I’m a Python guy, so naturally, I reached for that. I started by installing Pillow – that’s the image processing library I usually use. I used pip install Pillow in my terminal. Easy peasy.
Loading and Inspecting
Next, I grabbed an image from Unsplash – just a random landscape photo. I saved it as . Then, I wrote a quick script to load it up and check its dimensions. Something like this:
from PIL import Image
img = *("*")
width, height = *
print(f"Width: {width}, Height: {height}")
Just wanted to make sure I knew what I was dealing with. I mean, gotta know your canvas, right?
Basic Manipulation – Resizing and Rotating
Alright, time to get my hands dirty! I started with something simple – resizing the image. I wanted to make it smaller. So I used the resize() method from Pillow. This is what I did:
new_width = width // 2
new_height = height // 2
resized_img = *((new_width, new_height))
resized_*("*")
Basically, I halved the width and height, and saved the new image. Looked decent enough! Then I thought, let’s rotate this sucker! I tried a 90-degree rotation:
rotated_img = *(90)
rotated_*("*")
Simple. And it worked! I also played around with different angles – 45, 180, even some weird fractional ones just to see what would happen.
Playing with Colors
Okay, resizing and rotating are cool and all, but let’s get into the fun stuff: colors! Pillow has a convert() method that lets you change the color mode of an image. I decided to try converting it to grayscale:
grayscale_img = *("L")
grayscale_*("*")
Instant black and white! It’s amazing how a simple change like that can totally transform the feel of an image. After that, I messed around with color channels. I tried splitting the image into its red, green, and blue components. It’s a bit more involved, but basically, I created three new images, each showing only one color channel.
Adding Some Filters
Now for the real fun. Pillow has a bunch of built-in filters you can apply to images using the ImageFilter module. I tried a few. First, I went for a blur:
from PIL import ImageFilter
blurred_img = *(*)
blurred_*("*")
Super easy, and definitely made the image look softer. Then, I tried sharpening it:
sharpened_img = *(*)
sharpened_*("*")
That made the details pop a bit more. I even tried an edge detection filter, which highlighted the edges in the image. It was cool to see how these simple filters could change the image so drastically.
What I Learned and Next Steps
So yeah, that’s pretty much what I did with “nia jaxx” this weekend. It was a good refresher on image manipulation with Pillow. I’m thinking of taking this further and experimenting with more complex stuff, like:
Creating some kind of image collage
Implementing some custom filters
Maybe even trying to detect objects in the image using OpenCV
Anyway, that’s it for now. I’ll keep you posted on my progress. Maybe “nia jaxx” will actually turn into something cool!