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

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
黄巍
字节跳动首席吃点心员
黄巍
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
This Web App lets you convert your Normal Image to a SKETCHED one within a minute

This Web App lets you convert your Normal Image to a SKETCHED one within a minute

Avinash M 25 Nov 10, 2022
GIMP script to export bitmap as GRAPHICS 4 file (aka SCREEN 5)

gimpfu-msx-gr4.py GIMP script to export bitmap as GRAPHICS 4 file (aka SCREEN 5). GRAPHICS 4 specs are: 256x212 (or 256x192); 16 color palette (from 5

Pedro de Medeiros 4 Oct 17, 2022
👾 Python project to help you convert any image into a pixel art.

👾 Pixel Art Generator Python project to help you convert any image into a pixel art. ⚙️ Developer's Guide Things you need to get started with this co

Atul Anand 6 Dec 14, 2022
Simple mathematical operations on image, point and surface layers.

napari-math This package provides a GUI interfrace for simple mathematical operations on image, point and surface layers. addition subtraction multipl

Zach Marin 2 Jan 18, 2022
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
A ray tracing render implemented using Taichi language.

A ray tracing render implemented using Taichi language.

Mingrui Zhang 45 Oct 23, 2022
Napari simpleitk image processing

napari-simpleitk-image-processing (n-SimpleITK) Process images using SimpleITK in napari Usage Filters of this napari plugin can be found in the Tools

Robert Haase 11 Dec 19, 2022
This app finds duplicate to near duplicate images by generating a hash value for each image stored with a specialized data structure called VP-Tree which makes searching an image on a dataset of 100Ks almost instantanious

Offline Reverse Image Search Overview This app finds duplicate to near duplicate images by generating a hash value for each image stored with a specia

53 Nov 15, 2022
display: a browser-based graphics server

display: a browser-based graphics server Installation Quick Start Usage Development A very lightweight display server for Torch. Best used as a remote

Szymon Jakubczak 205 Oct 17, 2022
A Python Script to convert Normal PNG Image to Apple iDOT PNG Image.

idot-png-encoder A Python Script to convert Normal PNG Image to Apple iDOT PNG Image (Multi-threaded Decoding PNG). Usage idotpngencoder.py -i inputf

Lrdcq 2 Feb 17, 2022
Music Thumbnail Maker

Music Thumbnail Installing pip install TMFrame

krypton 4 Jan 28, 2022
PyGram Instagram-like image filters.

PyGram Instagram-like image filters. Usage First, import the client: from filters import * Instanciate a filter and apply it: f = Nashville("image.jp

Ajay Kumar Nagaraj 102 Feb 21, 2022
Rembg is a tool to remove images background.

Rembg is a tool to remove images background.

Daniel Gatis 7.8k Jan 05, 2023
Sombra is simple Raytracer written in pure Python.

Sombra Sombra is simple Raytracer written in pure Python. It's main purpose is to help understand how raytracing works with a clean code. If you are l

Hernaldo Jesus Henriquez Nuñez 10 Jul 16, 2022
Ascify-Art - An easy to use, GUI based and user-friendly colored ASCII art generator from images!

Ascify-Art This is a python based colored ASCII art generator for free! How to Install? You can download and use the python version if you want, modul

Akash Bora 14 Dec 31, 2022
Plots the graph of a function with ASCII characters.

ASCII Graph Plotter Plots the graph of a function with ASCII characters. See the change log here. Developed by InformaticFreak (c) 2021 How to use py

InformaticFreak 2 Apr 29, 2022
MyPaint is a simple drawing and painting program that works well with Wacom-style graphics tablets.

MyPaint A fast and dead-simple painting app for artists Features Infinite canvas Extremely configurable brushes Distraction-free fullscreen mode Exten

MyPaint 2.3k Jan 01, 2023
This is a python project which detects color of an image when you double click on it.

This is a python project which detects color of an image when you double click on it. You have to press ESC button to close the pop-up Image window. There are mainly two library CV2 and Pandas that a

Yashwant Kumar Singh 0 Aug 16, 2022
Extract the ISO 11146 beam size from an image file

laserbeamsize Simple and fast calculation of beam sizes from a single monochrome image based on the ISO 11146 method of variances. Some effort has bee

Scott Prahl 21 Jan 06, 2023