Logo

dev-resources.site

for different kinds of informations.

Dall.E Image Gen, And Size Comparison Of Image Formats

Published at
2/19/2024
Categories
ai
image
compression
ffmpeg
Author
crawlingcrusader
Categories
4 categories in total
ai
open
image
open
compression
open
ffmpeg
open
Author
16 person written this
crawlingcrusader
open
Dall.E Image Gen, And Size Comparison Of Image Formats

Image Gen And Conversion

Of late images generated via Dall.E can be downloaded only as .webp. This is slightly annoying because of it limited integration, for instance you can't upload a .webp image to twitter. This is only a minor inconvenience because you can easily convert webp to png image using ffmpeg.

ffmpeg -i input_image.webp output_image.webp
Enter fullscreen mode Exit fullscreen mode

Now, why would open AI do such a thing? If I remember correctly the images weren't available as png directly.

Well, webp images are smaller in size, hence lower storage and egress cost (if any).

Comparison

Now I wanted to know how much a size difference are we really talking about. So I generated an image using Dalle.E, downloaded it as web and converted to a couple other formats.
Here's the generated image:

Image description

The chart below shows the difference in image size

image size comparison

As you can see, its a pretty steep increase in size when an image goes from webp to png.

I generated this chart using GPT-4. Here's the prompt that I used:

can you generate a bar chart for me, here's the x, and y data
x: jpg, webp, tiff, png
y: 160, 494, 1500, 2300
label for x: image format
label for y: image size in KB

One might wonder, why is there a difference in size when its the same image? The answer is difference in compression techniques.
JPEG format uses lossy compression, which means some data points from image are lost. Which means every time you edit a jpeg image some data is lost, and the image size decreases.
To further illustrate this I converted the same image to jpeg multiple.
Basically running following command:

ffmpeg -i silicon-road2.jpg silicon-road.jpg
Enter fullscreen mode Exit fullscreen mode

to convert, and then run it again on the output.
With every iteration there was minor change in size. The chart below shows the trend for 5 iteration

jpeg conversion trend

Side note : I wrote a script and ran it for 100 iteration.
The image size stabilised after 9th iteration. Yet to figure out the exact science behind this.
Script:

#!/bin/bash

input="silicon-road.jpg"

# Loop 100 times
for i in $(seq 1 100)
do
    output="silicon-road${i}.jpg"

    ffmpeg -i "$input" "$output"

    input="$output"
done
Enter fullscreen mode Exit fullscreen mode

On the other hand PNG uses lossless compression which mean all the data points are preserved. Running the conversion operation has no impact on the image size.

What Did We Lose

Here's the original image:

original

Here's the image after 10 conversions:

Image description

It can be hard or near impossible to notice any difference with naked eye. So we'll run following command to get the 'difference' :

ffmpeg -i silicon-road.jpg -i silicon-road10.jpg -filter_complex "[0][1]blend=all_mode=difference" difference.png
Enter fullscreen mode Exit fullscreen mode

The command is essentially comparing (subtracting) the color value of each pixel. This way pixels with bigger difference will appear brighter.

Here's what the difference looks like:
difference

There's isn't a whole lot going on, so let's take a look at the difference between the jpeg, and png image:

Image description

This ends my detour of image size comparison. I better get back to the task at hand.

ffmpeg Article's
30 articles in total
Favicon
Desvendando Subprocessos: Criando um Bot de Música com Go
Favicon
Video data IO through ffmpeg subprocess
Favicon
Wisper, ffmpeg을 활용한 비디오 자막 자동 생성
Favicon
Integrating MinIO notifications with your Node.js service, FFmpeg, and Mozilla convert API.
Favicon
Cliet-side WebM/MP4 export from React.js Canavs Animation using ffmpeg.wasm for an Upwork client
Favicon
Reduce bitrate using FFMPEG
Favicon
Add a Watermark to a Video Using VideoAlchemy
Favicon
No Bullshit Guide to Youtube shorts automation in NodeJS, OpenAI, Ollama, ElevanLabs & ffmpeg
Favicon
Building a Video Streaming Platform with Node.js, FFmpeg, and Next.js
Favicon
Record Windows Screen using ffmpeg and convert to time lapse video
Favicon
Introducing Comet: A Free, Cross-Platform Video Converter Powered by FFmpeg
Favicon
Compress, Convert and Trim Videos with Command Line
Favicon
เผื่อใครอยากทำ mp4 to gif แบบคมๆ
Favicon
How to generate thumbnails from video ?
Favicon
Convert .caf to mp3 by Directory
Favicon
FFMPEG
Favicon
Run ffmpeg within a Docker Container: A Step-by-Step Guide
Favicon
New to DEV.to - About me
Favicon
Streaming Video to AWS MediaConnect Using FFmpeg and SRT Protocol: A Complete Guide
Favicon
Displaying a video on a ESP32 powered SSD1306 OLED screen
Favicon
FFMPEG Libraries - RTSP Client Keep Alive
Favicon
From Pixels to Playbacks: Dominate Multimedia with FFmpeg in Python
Favicon
Access webcam by ffmpeg in Windows
Favicon
OSCAR 2022 sea surface velocity streamplot animation
Favicon
Mastering Video Previews: A Guide to Compressed Videos and Thumbnails
Favicon
Dall.E Image Gen, And Size Comparison Of Image Formats
Favicon
AIS vessel density maps with pyspark and h3 and animations with ffmpeg
Favicon
Using Electron to create videos (Canvas + FFmpeg)
Favicon
BMF 📹 + Hugging Face🤗, The New Video Processing BFFs
Favicon
Leveraging GPU Acceleration in BMF for High-Performance Video Processing

Featured ones: