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

Use JpegTurbo.jl to load .jpg images #216

Closed
lorenzoh opened this issue Apr 20, 2022 · 3 comments · Fixed by #219
Closed

Use JpegTurbo.jl to load .jpg images #216

lorenzoh opened this issue Apr 20, 2022 · 3 comments · Fixed by #219
Labels
enhancement New feature or request

Comments

@lorenzoh
Copy link
Member

JpegTurbo.jl can speed up image loading quite a bit, and the previous ImageIO.jl versions had severe performance regressions for 1.7, which should be fixed if JpegTurbo.jl is used.

@lorenzoh lorenzoh added the enhancement New feature or request label Apr 20, 2022
@lorenzoh
Copy link
Member Author

@johnnychen94 Will JpegTurbo.jl be used automatically if people use up-to-date FileIO.jl versions or do I need to change something explicitly? Would like users to avoid the performance regression introduced in 1.7 of the old jpg loader.

@johnnychen94
Copy link
Contributor

johnnychen94 commented Apr 20, 2022

TL;DR; add ImageIO to Project.toml without using ImageIO in src/FastAI.jl. #219 is sufficient for this purpose.


Let me try to explain the FileIO strategy a bit. FileIO maintains a registry for various IO backends. For instance, there are four backends supporting JPEG format, i.e.,:

# Among the JPEG backends, JpegTurbo has the highest priority, QuartzImageIO is only available on macOS
add_format(
    format"JPEG",
    UInt8[0xff,0xd8,0xff],
    [".jpeg", ".jpg", ".JPG"],
    [idJpegTurbo],
    [idImageIO],
    [idQuartzImageIO, OSX],
    [idImageMagick]
) # 0xe1

Thus, when you try to do load("file.jpg"), FileIO will try to do using JpegTurbo and call JpegTurbo's load function. If this fails, then try the next one until it succeeds.

ImageIO contains no real codes, it borrows the functionality from JpegTurbo.jl and other backends. We (JuliaImages) aim to make ImageIO the default IO backend and we want to tell our users a simple answer for all similar questions, that is:

add ImageIO "somewhere", use FileIO's load/save. By adding ImageIO in FastAI's Project.toml file, you can ensure that every user of FastAI has ImageIO installed "somewhere".

the previous ImageIO.jl versions had severe performance regressions for 1.7

This is a bit incorrect. Before I wrote the JpegTurbo.jl, ImageMagick was the only IO backend for the JPEG format, so when you saw load("file.jpg") getting slow by a significant ratio, it's because ImageMagick is getting slow, which is now fixed in Julia 1.8.

@lorenzoh
Copy link
Member Author

Thanks for the fix and the explanation!

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

Successfully merging a pull request may close this issue.

2 participants