Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BioImage Analysis]: Zooming in #237

Open
haesleinhuepf opened this issue Feb 18, 2025 · 3 comments
Open

[BioImage Analysis]: Zooming in #237

haesleinhuepf opened this issue Feb 18, 2025 · 3 comments

Comments

@haesleinhuepf
Copy link
Owner

I need Python code for zooming into an image iteratively. In a for-loop the image is cropped around its center keeping just 90% of image width and height. The cropped image is stored in a list before this image is cropped in the next iteration. We do this 20 times and afterwards, the resulting list of images is shown using stackview.animate(image_list).

git-bob comment on how to do this

Copy link
Contributor

This message was generated by git-bob (version: 0.19.0, model: claude-3-5-sonnet-20241022, log), an experimental AI-based assistant. It can make mistakes and has limitations. Check its messages carefully.

Let me help you with iterative image zooming. Here's a Jupyter notebook that demonstrates the solution:

import numpy as np
from skimage import data
from stackview import animate

# Load a sample image
image = data.camera()

# Create list for storing zoomed images
image_list = []

# Store original image
image_list.append(image)

# Current image
current_image = image.copy()

# Zoom 20 times
for i in range(20):
    # Get current dimensions
    height, width = current_image.shape
    
    # Calculate new dimensions (90% of current)
    new_height = int(height * 0.9)
    new_width = int(width * 0.9)
    
    # Calculate crop coordinates
    start_y = (height - new_height) // 2
    start_x = (width - new_width) // 2
    
    # Crop image
    current_image = current_image[start_y:start_y + new_height, 
                                start_x:start_x + new_width]
    
    # Store cropped image
    image_list.append(current_image)

# Animate the zoom sequence
animate(image_list)

This creates a zoom-in effect by iteratively cropping 90% of the image around its center. The animation will show the progressive zoom-in sequence.

@haesleinhuepf
Copy link
Owner Author

Very cool! Git-bob try this in a notebook! And please add the parameter filename="test.gif" to the animate function.

Copy link
Contributor

This message was generated by git-bob (version: 0.19.0, model: claude-3-5-sonnet-20241022, log), an experimental AI-based assistant. It can make mistakes and has limitations. Check its messages carefully.

I helped implement a zooming animation feature by creating a Jupyter notebook that demonstrates iterative image cropping. The code takes an input image and creates a sequence of progressively zoomed-in versions by cropping 90% of the image dimensions around its center in each iteration. I used skimage's camera image as a demo and stored the sequence in a list that was then animated using stackview.animate. The animation was saved as a GIF file for easier sharing and visualization of the zoom effect.

  • test.gif Generated GIF animation showing the progressive zoom-in effect on the camera image.
  • zoom_demo.ipynb Created Jupyter notebook containing the image zooming code with animation export functionality.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant