This project provides a simple image magnifier tool built in Processing. It allows users to zoom in on specific areas of an image and view them in detail. The magnifier works by enlarging the pixels within a region and drawing them as vectors.
- Written in Processing 4.3
- No special libraries required.
- Open the project in a Processing environment. Ensure you have Processing installed on your system.
- Place an image file named "image.jpg" in the same directory as the sketch. This image will be loaded and used for magnification.
- Run the sketch. The sketch will launch a window displaying the image.
- Use the mouse wheel to zoom in and out. Scrolling up will zoom in, while scrolling down will zoom out.
- Move the mouse cursor over the image to magnify the area around it. The magnified area will be displayed in a circular region centered around the cursor.
-
Saving Drawing State: The
pushMatrix()
function saves the current drawing state. This includes any transformations such as translation and scaling. -
Translation: The
translate(mouseX, mouseY)
function translates the coordinate system so that it is centered around the current mouse position. This ensures that the magnification effect follows the mouse cursor. -
Scaling: The
scale(scaleFactor)
function scales the coordinate system by thescaleFactor
variable. This effectively zooms in or out on the image, depending on the value ofscaleFactor
. -
Iterating Through Pixels: Nested loops iterate through all the pixels within the magnified area. For each pixel, the code calculates its distance from the center of the magnifier.
-
Conditional Check: It checks if the distance of the pixel from the center is within the specified
magnifySize
scaled by thescaleFactor
. If it is, the pixel is considered to be within the magnified area. -
Pixel Enlargement: For pixels within the magnified area, the code retrieves the color of the corresponding pixel from the original image using
img.get(x, y)
. -
Visual Representation: The magnified pixels are represented by enlarged rectangles, giving the impression of magnification.
-
Restoring Drawing State: Finally, the
popMatrix()
function restores the previous drawing state saved bypushMatrix()
. This ensures that subsequent drawing operations are not affected by the transformations applied for magnification.
- Circular Masking: Circular masking is used to define the area of magnification, ensuring that only the pixels within this circular region are enlarged.
- Zoom Controls: Zooming functionality is implemented using mouse wheel events, allowing users to zoom in and out seamlessly.
- Visual Feedback: The zoom level and magnification ring provide visual feedback to the user, enhancing the interactive experience.
The hardest part was probably the for loop to go through the pixels in an area. But I remember Tom showing us this method in one of his real life lectures, so I just added it in. Most of the solutions to do this were easy to find from the Processing documentation, and from the online lectures.
A code project by Wong Jo-Hann
23/24 Computational Practices: Sound and Image Processing
Creative Computing BSc class
UAL CCI University Of the Arts London