Skip to main content

Connecting fast.ai with RawPy

Here we can make fast.ai framework support RawPy library, hence use RAW image files on fastai.

The list of all the RAW image files that can be supported by rawpy (based on LibRaw):

https://www.libraw.org/supported-cameras

Partial list of the supported RAW formats:

  • *.IIQ (Phase One)
  • *.3FR (Hasselblad)
  • *.DCR, *.K25, *.KDC (Kodak)
  • *.CRW *.CR2 *.CR3 (Canon)
  • *.ERF (Epson)
  • *.MEF (Mamiya)
  • *.MOS (Leaf)
  • *.NEF *.NRW (Nikon)
  • *.ORF (Olympus)
  • *.PEF (Pentax)
  • *.RW2 (Panasonic)
  • *.ARW, *.SRF, *.SR2 (Sony)

How to install

Use:

pip install fastai-rawpy

to install this package.

How to import fastai-rawpy

Use:

from fastairawpy import *

in order to import RawImageBlock as well as all of the necessary functions/classes/etc that adjust fast.ai so it supports RawPy.

How to use fastai-rawpy

Upon using fast.ai, wherever you could have used ImageBlock, just type in RawImageBlock.

Examples

example (1)

dblock = DataBlock(blocks=(ImageBlock(cls=PILImage),Categorize))

This line creates two blocks (input and target) of an ImageBlock, that is a transform to be applied to create items of image type. The transform uses PILImage as a data-holder of the image files (such as JPG, PNG, BMP, ...).

dblock = DataBlock(blocks=(RawImageBlock,Categorize))

But this line uses RawImageBlock transform, that is applied automatically on built-in RAWImage items. RAWImage is a data-holder of RAW image files, alike PILImage, but is based on rawpy package.

example (2)

This line code snippet creates two RawImageBlock blocks of input and target, where the parameters being passed in define the postprocessing of each blocks' image:

dblock = DataBlock(blocks=(RawImageBlock(  # Input
                                         gamma=(2.222, 4.5),                 # Gamma values
                                         output_color=rawpy.ColorSpace.sRGB, # sRGB Color Space
                                         output_bps=16),                     # Bits_per_pixel 
                           RawImageBlock( # Target
                                         use_camera_wb=True,                 # White blanace
                                         output_color=rawpy.ColorSpace.sRGB, # sRGB Color Space
                                         output_bps=16)                      # Bits_per_pixel 
                           )
                    )

The full list of parameters: https://letmaik.github.io/rawpy/api/rawpy.Params.html

Why use fastai-rawpy

RAW format has a bit-depth of 16bits for every channel (R,G,B[,G]), meaning: every pixel gets values in between 0 up to... 65535!

2^16=65536

Therefore, a RAW image file would normally have a larger range of values for every pixel. This can help training a model become more precise, when switching from JPG to RAW.

Note: in practice, every DSLR stores RAW files and postprocesses these files into other formats such as JPG. For instance, it crops and compresses the JPG image out of the RAW file.

Performance

Behind the stage

New objects that create the bond between fast.ai and rawpy

class TensorRawImage + class RAWImage

Metadata

Release files for fastai-rawpy 0.0.15

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fastai-rawpy 0.0.15
File Size Uploaded
fastai-rawpy-0.0.15.tar.gz 15.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for fastai-rawpy 0.0.15
File Interpreter ABI Platform
fastai_rawpy-0.0.15-py3-none-any.whl Python 3 none any Details

Total release size: 31.4 kB

Release files / fastai-rawpy-0.0.15.tar.gz

Download URL fastai-rawpy-0.0.15.tar.gz
Size 15.6 kB
Tags Source
SHA-256 checksum
How to use checksums
2a7bd54b9b4441cb78e56c08f4b74111c678d3820a3866343a14734fbe6759b9
BLAKE2b-256 checksum
How to use checksums
ca0141ecf520de4f0225506e4329dd4b50715124736f1d72aeb37ea32911ab30
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.2

Release files / fastai_rawpy-0.0.15-py3-none-any.whl

Download URL fastai_rawpy-0.0.15-py3-none-any.whl
Size 15.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
74715ad41e5bb564b22711b38f360308478210b4a73d06fd08bd2548882b09bc
BLAKE2b-256 checksum
How to use checksums
a694f0b8823b1f4bd26ee80238ca6b48e7de184df4b290df9cc38845bf2dd569
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.2

Release history Release notifications | RSS feed

This release

0.0.15 This release

2 release files

0.0.14

2 release files

0.0.13

2 release files

0.0.12

2 release files

0.0.11

2 release files

0.0.10

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

1 release file

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page