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

Makeanimationupdate #523

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Conversation

thekester
Copy link
Contributor

@thekester thekester commented Jul 29, 2024

Hello, this pull request addresses issue #522 by adding new functionality to create and update animations from a series of images. It includes the following key changes:

    i)  Function to Resize Images:
        Added `resize_image_to_fixed_size(image, size=(2864, 1440))` function to ensure all images are resized to a consistent size for the animation.

    ii) Function to Load and Resize Images:
        Introduced` load_and_resize_images(image_folder, size=(2864, 1440))` to load images from a specified folder and resize them.

   iii) Function to Create Animation:
        Developed create_animation(image_folder, output_file, fps=4, size=(2864, 1440), probesize=5000000) to compile images into a video file.The function checks for consistent image sizes and raises an error if discrepancies are found.

    iv) Convenience Function to Make MP4 Animation:
        Added make_animation_mp4(filepath_images, fps, fn_out) to simplify the creation of MP4 animations.

Changes made in SDS_tools and include 2 librariesimport cv2 from PIL import Image to implement them, replace pip install pyqt5 imageio-ffmpeg with pip install pyqt5 imageio-ffmpeg opencv-python Pillow

@kvos
Copy link
Owner

kvos commented Aug 21, 2024

hi @thekester , sorry I took 3 weeks to review this. I like the PR so that we don't get that warning anymore but I prefer not to add another module like opencv as there are now other toolkits that share dependencies with coastsat (like coastseg). So would there be a way to avoid the warning without bringing in new packages?

@thekester
Copy link
Contributor Author

thekester commented Aug 21, 2024

Since Pillow is already a dependency of matplotlib (matplotlib) and we have imageio, there’s definitely a way to avoid the warning without implementing OpenCV. I’m working on a solution using these existing libraries, and I’ll add the commit to the PR shortly (add on (https://github.com/kvos/CoastSat/pull/523/commits/ef71e417d234f476094cd73de498cc8f16795289 )

@kvos
Copy link
Owner

kvos commented Aug 23, 2024

thanks! will test it

@kvos
Copy link
Owner

kvos commented Aug 28, 2024

@thekester , was wondering why we need to resize the image to 2864, 1440? this may create animations that are quite large no?

@thekester
Copy link
Contributor Author

Please feel free to choose the most appropriate size; the example provided size=(2864, 1440) is just a suggestion. The goal is to ensure all images are the same size before creating the animation, thereby avoiding the IMAGEIO FFMPEG WRITER WARNING.

@kvos
Copy link
Owner

kvos commented Sep 2, 2024

@thekester , I'm not convince about the resizing as every ROI has a different aspect ratio, some beaches are E or W facing while other are N or S facing, then if you resize all the images to a fixed size it will not work. I am happy to live with the warning as it seems to create good quality clips anyways. But if you want to resize, I suggest you find the most common size in the image folder and use that size for resizing all the images. It can happen that some satellite images are clipped, hence the difference in size that ffpmeg doesn't like.
Something like this:

list_files = sorted(os.listdir(filepath_images))
sizes = [Image.open(os.path.join(filepath_images,_)).size for _ in list_files]
unique_sizes = set(sizes)
# select most common size

@thekester
Copy link
Contributor Author

thekester commented Sep 2, 2024

Thank you for your feedback, @kvos. I hadn't considered the issue of different aspect ratios due to the varying orientations of the beaches—this is a great point. I'll look into a method to automatically detect the aspect ratio of each image, identifying whether the beaches are oriented East-West or North-South. Then, I can adjust the resizing process to maintain the original proportions of the images while still avoiding the IMAGEIO FFMPEG warnings.

I'll test this approach and add a commit if it works.

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

Successfully merging this pull request may close these issues.

2 participants