<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/medium-w45pxizaf" -->

---
title: Medium | daily.dev
description: A developer built `dct-vision`, a Python library that processes JPEG images directly on their DCT (Discrete Cosine Transform) coefficients rather than decoding...
canonical: https://daily.dev/posts/medium-w45pxizaf
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Medium | daily.dev
og:description: A developer built `dct-vision`, a Python library that processes JPEG images directly on their DCT (Discrete Cosine Transform) coefficients rather than decoding...
og:url: https://daily.dev/posts/medium-w45pxizaf
og:image: https://api.daily.dev/og/posts/W45PxIZAF.png
og:image:alt: Medium
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Medium

**[Medium](https://daily.dev/sources/medium_js)** · 7 min read · 5 upvotes · 0 comments

## Summary

A developer built `dct-vision`, a Python library that processes JPEG images directly on their DCT (Discrete Cosine Transform) coefficients rather than decoding to pixels first. The post gives an honest benchmark comparison against Pillow and OpenCV, showing where the frequency-domain approach wins (pointwise operations, lossless transforms like flips and rotations, batch pipelines) and where it loses (cheap geometric ops and resampling where OpenCV's SIMD-optimized routines dominate). A key insight: measuring the full pipeline (load, operate, save) rather than just the operation in isolation changes the conclusions significantly. The author also shares a bug story where direction-only unit tests passed but quality metrics (PSNR/SSIM) revealed a factor-of-8 error in the brightness operation. On the ML side, DCT inputs train 7–8x faster than pixel inputs but don't match pixel accuracy on small images like CIFAR-10 due to spatial resolution loss from 8x block downsampling — a tradeoff that disappears on larger ImageNet-scale images. Practical use cases highlighted include JPEG forensics, deepfake/GAN detection, and thumbnail generation (DC coefficients give a free 8x-downscaled preview).

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://medium.com/@adari.girishkumar/i-built-a-jpeg-native-image-processing-library-827c5fce8506>

## Questions this post answers

### Why is working on JPEG DCT coefficients directly faster than decoding to pixels first for some operations?

Because JPEG already stores images as frequency coefficients from 8x8 block DCTs, and many classical operations have direct frequency-domain equivalents via the convolution theorem: blur becomes multiplying coefficients by a Gaussian envelope, brightness becomes adding to the DC coefficient, and sharpening becomes boosting high frequencies, all without ever decoding to pixels.

_Developers optimizing image pipelines can find deep dives like this DCT approach through daily.dev._

### Are horizontal flips, cropping, and 90-degree rotations on JPEG images lossless when done via DCT coefficient manipulation?

Yes, horizontal and vertical flips, cropping, brightness adjustment, and 90/180/270 degree rotations are exact coefficient permutations requiring no inverse DCT or re-encode, resulting in zero quality loss. This is the same technique jpegtran uses under the hood, and it comes at essentially no computational cost.

_Anyone chasing lossless JPEG transforms can track techniques like this through daily.dev._

### Does training a CNN on DCT coefficients instead of RGB pixels hurt accuracy on CIFAR-10?

Yes, DCT input trains CNNs and ResNet-18 seven to eight times faster on CIFAR-10 but does not match pixel accuracy, because CIFAR images are only 32x32 and the DCT's 8x block downsampling collapses that to a 4x4 coefficient grid, losing spatial detail. Adding YCbCr color to the DCT input recovers 4 to 7 accuracy points versus using luminance alone.

_Engineers weighing DCT-based speedups against accuracy trade-offs can follow experiments like this on daily.dev._

## Similar posts on daily.dev

- [How JPEG works: Interactively explore JPEG's lossy compression methods](https://daily.dev/posts/how-jpeg-works-interactively-explore-jpeg-s-lossy-compression-methods-thgyhxnvu) · Hacker News · 0 upvotes · 0 comments
- [Richard Geldreich's Blog: Neural texture decoders can suppress DCT ringing artifacts within latent features](https://daily.dev/posts/richard-geldreich-s-blog-neural-texture-decoders-can-suppress-dct-ringing-artifacts-within-latent-f-nte5fxzpl) · Richard Geldreich's Blog · 0 upvotes · 0 comments
- [I built a Python utility using Claude to automate my image editing workflow, and it saves me hours every week](https://daily.dev/posts/i-built-a-python-utility-using-claude-to-automate-my-image-editing-workflow-and-it-saves-me-hours-e-bxb77ra5k) · XDA Developers · 1 upvotes · 0 comments
- [What Matters in Practical Learned Image Compression](https://daily.dev/posts/what-matters-in-practical-learned-image-compression-p0avkudfo) · Hacker News · 0 upvotes · 0 comments
- [Face Recognition on One CPU Core: I Tested 28 Video Pipelines and the Biggest Model Didn’t Always Win](https://daily.dev/posts/face-recognition-on-one-cpu-core-i-tested-28-video-pipelines-and-the-biggest-model-didn-t-always-wi-zy7zdtdkx) · Medium · 0 upvotes · 0 comments

---

Tags: [#python](https://daily.dev/tags/python), [#pytorch](https://daily.dev/tags/pytorch), [#image-processing](https://daily.dev/tags/image-processing)

[View this post on daily.dev](https://daily.dev/posts/medium-w45pxizaf)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Medium","url":"https://daily.dev/posts/medium-w45pxizaf","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/medium-w45pxizaf"},"datePublished":"2026-07-18T03:31:00.703Z","dateModified":"2026-09-13T21:05:14.941Z","description":"A developer built `dct-vision`, a Python library that processes JPEG images directly on their DCT (Discrete Cosine Transform) coefficients rather than decoding...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/53d69fc3fdb92dd816154088509ff906?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/53d69fc3fdb92dd816154088509ff906?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"Medium","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Medium","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1/logos/medium","url":"https://daily.dev/sources/medium_js"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/medium-w45pxizaf","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":5},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"python,pytorch,image-processing","timeRequired":"PT7M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Medium","item":"https://daily.dev/sources/medium_js"},{"@type":"ListItem","position":3,"name":"Medium"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/medium-w45pxizaf#faq","mainEntity":[{"@type":"Question","name":"Why is working on JPEG DCT coefficients directly faster than decoding to pixels first for some operations?","acceptedAnswer":{"@type":"Answer","text":"Because JPEG already stores images as frequency coefficients from 8x8 block DCTs, and many classical operations have direct frequency-domain equivalents via the convolution theorem: blur becomes multiplying coefficients by a Gaussian envelope, brightness becomes adding to the DC coefficient, and sharpening becomes boosting high frequencies, all without ever decoding to pixels. Developers optimizing image pipelines can find deep dives like this DCT approach through daily.dev."}},{"@type":"Question","name":"Are horizontal flips, cropping, and 90-degree rotations on JPEG images lossless when done via DCT coefficient manipulation?","acceptedAnswer":{"@type":"Answer","text":"Yes, horizontal and vertical flips, cropping, brightness adjustment, and 90/180/270 degree rotations are exact coefficient permutations requiring no inverse DCT or re-encode, resulting in zero quality loss. This is the same technique jpegtran uses under the hood, and it comes at essentially no computational cost. Anyone chasing lossless JPEG transforms can track techniques like this through daily.dev."}},{"@type":"Question","name":"Does training a CNN on DCT coefficients instead of RGB pixels hurt accuracy on CIFAR-10?","acceptedAnswer":{"@type":"Answer","text":"Yes, DCT input trains CNNs and ResNet-18 seven to eight times faster on CIFAR-10 but does not match pixel accuracy, because CIFAR images are only 32x32 and the DCT's 8x block downsampling collapses that to a 4x4 coefficient grid, losing spatial detail. Adding YCbCr color to the DCT input recovers 4 to 7 accuracy points versus using luminance alone. Engineers weighing DCT-based speedups against accuracy trade-offs can follow experiments like this on daily.dev."}}]}
```

