【萝莉图片算法】高损图像压缩算法!?

Overview

【萝莉图片算法】高损图像压缩算法!?

我又发明出新算法了!

这次我发明的是新型高损图像压缩算法——萝莉图片算法!为什么是萝莉图片,这是因为它是使动用法,让图片变小所以是萝莉图片,大家一定要学好语文哦!

压缩效果

太神奇了!压缩率竟然高达99.97%!

./文档/22.webp

与常见压缩算法对比

在图片最终大小为1KB的情况下,我们将萝莉图片与JPG、PNG、WEBP比较——

./文档/1.jpg

看起来萝莉图片算法的质量还不错!

不过其他算法设成最低质量也压不到1KB,所以原图是提前压过分辨率的。

原理

原理非常简单——如果莉沫酱在白纸上画长方形,只要她画得足够多,就可以画出任何的图像细节。而如果能画得准确,她就可以用少量的数据来表示出画像的主体部分。

这里用了一个简单的贪心算法来计算每一个长方形的画法,我们设置一个代价函数作为贪的目标,是让原图和目标图的每个像素的误差的平方和(SE)最小。

我们每次暴搜一个长方形的左上角和右下角,假设将原图中长方形内部的所有像素取均值作为压缩图的长方形填充颜色,以此来减小SE。然后把那个最能削减SE的长方形真正地填上。

嗯,就是这么简单。

对了,顺便一说我写完以后发现这个代价函数好像是可以优化到O(1)的但是我太累了动不了了……下次再写吧。

安装和使用方法

首先你需要一个Python3.6以上版本。

然后——

pip install git+https://github.com/RimoChan/loliimg.git

装好之后在要用的时候import就行啦!

import cv2
import loliimg

img = cv2.imread('ori.png')
res = loliimg.ride(img, 3, verbose=False)
for pos, color in res:
    print(pos, color)

打出来之后你就可以拿着poscolor去干一些别的事情,比如生成SVG之类的。

接口只有1个,是loliimg.ride,长这样——

def ride(真原图, epoch, 中间结果存储位置=None, verbose=True): 
    ...

参数第一个是输入的图片,3维度的np.array,第二个是要跑多少轮,第三个是中间结果存储位置,一个Path字符串,第四个是要不要显示每个epoch的进度条。

Owner
黄巍
字节跳动首席吃点心员
黄巍
Converting Images Into Minecraft Houses

Converting Images Into Minecraft Houses In this particular project, we turned a 2D Image into Minecraft pixel art and then scaled it in 3D such that i

Mathias Oliver Valdbjørn Jørgensen 1 Feb 02, 2022
Samila is a generative art generator written in Python

Samila is a generative art generator written in Python, Samila let's you create arts based on many thousand points. The position of every single point is calculated by a formula, which has random par

Sepand Haghighi 947 Dec 30, 2022
Python avatar generator for absolute nerds

pagan Welcome to the Python Avatar Generator for Absolute Nerds. Current version: 0.4.3 View the change history here. Remember those good old days whe

David Bothe 280 Dec 16, 2022
Image Compression GUI APP Python: PyQt5

Image Compression GUI APP Image Compression GUI APP Python: PyQt5 Use : f5 or debug or simply run it on your ids(vscode , pycham, anaconda etc.) socia

Sourabh Dhalia 1 May 21, 2022
Image2scan - a python program that can be applied on an image in order to get a scan of it back

image2scan Purpose image2scan is a python program that can be applied on an image in order to get a scan of it back. For this purpose, it searches for

Kushal Shingote 2 Feb 13, 2022
SALaD (Semi-Automatic Landslide Detection) is a landslide mapping system

SALaD (Semi-Automatic Landslide Detection) is a landslide mapping system. SALaD utilizes Object-based Image Analysis and Random Forest to map landslides.

NASA 14 Jan 04, 2023
A utility for quickly cropping large collections of images.

Crop Tool A utility for quickly cropping large collections of images. Inspired by Derrick Schultz's dataset-tools. Setup It's suggested that you use A

dusk (they/them) 6 Nov 14, 2021
This is an app that allows users to upload photos and display and store the photos in a file until the user deletes them.

Qt Photo App This is an app that allows users to upload photos and display and store the photos in a file until the user deletes them. Setup python3 -

Kathy Yang 5 Jan 22, 2022
python binding for libvips using cffi

README PyPI package: https://pypi.python.org/pypi/pyvips conda package: https://anaconda.org/conda-forge/pyvips We have formatted docs online here: ht

libvips 467 Dec 30, 2022
image-processing exercises.

image_processing Assignment 21 Checkered Board Create a chess table using numpy and opencv. view: Color Correction Reverse black and white colors with

Benyamin Zojaji 25 Dec 15, 2022
Water marker for images.

watermarker linux users: To fix this error,please add truetype font path File "watermark.py", line 58, in module font = ImageFont.truetype("Dro

13 Oct 27, 2022
A simple plugin to view APR images in napari

napari-apr-viewer A simple plugin to view APR images in napari This napari plugin was generated with Cookiecutter using @napari's cookiecutter-napari-

5 Jan 24, 2022
Anime2Gif - an algorithm that detects scenes in a video and generates gifs from it

Anime2Gif Anime2Gif is an algorithm that detects scenes in a video and generates gifs from it. How to use To use it, first, you'll need to install it'

1 Dec 09, 2021
Maze generator with most popular shapes - hexagon, triangle, square

Maze-Generator Maze generator with most popular shapes - hexagon, triangle, square (sqaure not implemented yet): Theory: Planar Graph https://en.wikip

Kacper Plesiak 2 Dec 28, 2021
A tool for hiding data inside of images

Stegenography-tool a tool for hiding data inside of images Quick test: do python steg-encode.py test/message.txt test/covid19.png to generate the test

luke 2 Nov 02, 2021
Image Processing HighPass Filter With Python

Image_Processing_HighPassFilter High Pass Filter take the high frequency and ignore the low frequency High Pass Filter can be use to sharpening an ima

Felix Pratamasan 1 Dec 27, 2021
impy is an all-in-one image analysis library, equipped with parallel processing, GPU support, GUI based tools and so on.

impy is All You Need in Image Analysis impy is an all-in-one image analysis library, equipped with parallel processing, GPU support, GUI based tools a

24 Dec 20, 2022
Convert bitmap images to seeds for Tiny-83 NFT project.

What is this? This tool allows you to convert any 14p high and 22p wide Bitmap (.bmp) to the seed needed for the Tiny-83 NFT project. Project Twitter:

shib_maximalist 1 Oct 31, 2021
Polyfoto - Create image mosaics.

Polyfoto Create image mosaics. Showcase "Before and After Science" by Brian Eno "Scott 3" by Scott Walker Installation Clone this repository to your l

Shane Drabing 149 Dec 25, 2022
Generative Art Synthesizer - a python program that generates python programs that generates generative art

GAS - Generative Art Synthesizer Generative Art Synthesizer - a python program that generates python programs that generates generative art. Examples

Alexey Borsky 43 Dec 03, 2022