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

Reading cropped frames #387

Open
juliohm opened this issue Jan 6, 2023 · 5 comments
Open

Reading cropped frames #387

juliohm opened this issue Jan 6, 2023 · 5 comments

Comments

@juliohm
Copy link

juliohm commented Jan 6, 2023

Is it possible to read crops of frames from disk, say frame[1:100,300:500]? We have these large images that we would like to read as efficiently as possible. Only a specific area is relevant for the calculations, and so reading the full frame to discard tons of pixels isn't very nice.

@IanButterworth
Copy link
Member

It's a little out of scope of this package, but if they're TIFFs you can via mmaping
https://tamasnagy.com/TiffImages.jl/stable/examples/mmap_lazyio/#Memory-mapping-and-lazy-loading

May be possible for other image formats too

@IanButterworth
Copy link
Member

Or by images do you mean frames from a video file?

@juliohm
Copy link
Author

juliohm commented Jan 6, 2023

I mean frames from a video file. Currently I don't know how to read just portions of a frame. I am reading whole frames and discarding most pixels.

@IanButterworth
Copy link
Member

I don't think this is supported in VideoIO. It might be possible but would require looking into whether av_image_copy_to_buffer or an equivalent can be set to target a crop region (into an appropriate buffer size)

@spm-sudo-echo
Copy link

I also face the same issue; I want to crop my video in time too.
I have stocked the desired images and saved them on the computer. However, making a video of those images is not encoded correctly, and certain portions must be cut. I don't know why.
I am using the following code:
imgnames = filter(x->occursin("jpg", x), readdir()) # Populate list of all images and sort them based on first numerics
intstrings = map(x->split(x,".")[1],imgnames) # Extract index from filenames
p = sortperm(parse.(Int,intstrings)) #sort files numerically
imgstack = []
for imgname in imgnames[p]
push!(imgstack,load(imgname))
end

encoder_options = (crf=15, preset="fast")
VideoIO.save("video.mp4", imgstack, framerate=25, encoder_options=encoder_options)

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

3 participants