Giter Site home page Giter Site logo

fflorezz / pixelglitch Goto Github PK

View Code? Open in Web Editor NEW

This project forked from volfegan/pixelglitch

0.0 1.0 0.0 8.31 MB

Image glitch visualization using various Pixel Sorting methods for Processing

License: MIT License

Processing 78.22% Java 21.78%

pixelglitch's Introduction

PixelGlitch

Image glitch visualization using various Pixel Sorting methods for Processing v3. This is a by-product from my pixel sorting library. I also included some external library sketches and all the credits and original source to their work is given in the source code and here.

- - -

Basic setup and config

Most of the processing sketches have the following common variables to control the visualization and sorting. Some sketches have their own option variables and they are at the start of the sketch with instruction with their meaning.

  • boolean showBothIMG -> can be either "true" or "false"; If true, it shows both imgs side by side, otherwise it only shows the sorted img with the original image in the corner reduced to 20% the size. If the image is bigger than the device's screen, it will rescale the image to 80% of the screen.
  • String sortPixelMethod -> can be either "hue" or "brightness". As the name sugests the user can select how to sort the pixels by hue or brightness
  • int glitchLevel -> each sorter has its own range of values. This is used to control intensity of glitch. More details are found on each individual method example.
  • int multiStep -> each sorter has its own value. This is used to control speed of sorting process. For each frame, the process will run a multiStep times.

- - -

Bellow the examples on how each glitch visualization method operates. I wrote a brief explanation of how each algorithm works on selecting the pixels and glitch an image. The example images are a good measure of the levels of glitch and how extensive it tarnishes the picture.

Personal created glitch library

Glitch by Imperfect selection Sorting

Based on Pixel Selection Sort and also as inefficient as that. The selection of each pixel is not done correctly because the swap of the selected Pixel step is still inside the loop that looks for all the pixels properties. This glitches the image in a very unique way, like a wind is blowing the pixels. Since the swap of the select pixel is based on a correct measure, but only transposed for a small distance, the glitch happens on localized places across the image. For a better effect, it is necessary several passes, but the problem is that the speed of this method is the same as the selection sort. It is very, very slow and the bigger the image, it gets exponentially slow.

Below two examples of an image glitched, with the pixels either sorted by hue or brightness:

Imperfect selection sorting of an sunflower

Glitch by Incomplete HeapSorting

Based on Pixel Heap Sorting. The glitchLevel range is [0, to..., 10]. The glitchLevel 0 to 9 are constructed by "heapify" the image array without doing the 1st "heapify" pass that creates the heap tree. The higher the level, more of the image is sorted, but in an incomplete form. The glitchLevel 10 is done by only doing the 1st "heapify" pass and not finishing the sorting, and that gives the tree-like appearance to image repeating itself.

Sorted by Hue:

Incomplete HeapSorting of an sunflower by hue

Sorted by Brightness:

Incomplete HeapSorting of an sunflower by brightness

Glitch by Incomplete Merge Sorting

Based on Pixel Merge Sorting. No difference from a normal Merge sorting. The glitchLevel range is [1, to...] and is used to control how many division|merges are done during the sorting before stopping.

Sorted by Hue:

Incomplete Merge Sorting of an sunflower by hue

Sorted by Brightness:

Incomplete Merge Sorting of an sunflower by brightness

Glitch by Incomplete Shell Sorting

Based on Pixel Shell Sorting. No difference from a normal Shell sorting. The glitchLevel range is [0, to...] and is used to control the size of the max gap interval of the pixel sorting (using the variable glitch) and stopping when the gap reaches the limit given. How this Pixel Shell sorting cuts and reassemble the image depends on the image width x height and the colour hue|brightness. As a general rule, when the width is wider than the height we see the image is also being cut vertically and horizontally. For this square dimension flower, we can only see the cuts being done horizontally.

Sorted by Hue:

Incomplete Shell Sorting of an sunflower by hue

Sorted by Brightness:

Incomplete Shell Sorting of an sunflower by brightness

3rd party imported and modified glitch library

Glitch by kimasendorf/ASDFPixelSort

Based on kimasendorf/ASDFPixelSort. This program is a bit famous, so I wanted to see how the visualization process of the glitch occur. The original program has 3 modes of pixel sorting and only does in one way (vertical (V) + horizontal (H)). I modified it so we can change the direction of the sorting in any combination of (V) and (H) sorting. This gives 12 ways of sorting differently. Since this was not made by me, the variable names are different (description below):

  • boolean mode = 0|1|2 -> mode is the Pixel sorter method to be used. [0]: will select pixels by getFirstNotBlackX() and then the getNextBlackY(); [1]: sort by brightness. It getFirstBrightX() and then getNextDarkY(); [2]: sort by getFirstNotWhiteX() and then getNextWhiteY(). Threshold values to determine how the pixel sorting starts and ends:
  • int blackValue = -16000000; //original -16000000
  • int brightnessValue = 60; //original 60
  • int whiteValue = -13000000; //original -13000000
  • int glitch = 0|1|2|3 -> Determines the direction of the glitch. [0]: 2x pass -> vertical (V) + horizontal (H); [1]: 2x pass -> horizontal (H) + vertical (V); [2]: 1x pass -> horizontal (H); [3]: 1x pass -> vertical (V). When there is 2x pass the glitch gets more intense.

Sorted by mode 0, respectively glitch: H, H+V, V, V+H

Glitch of an sunflower by kimasendorf mode 0

Sorted by mode 1, respectively glitch: H, H+V, V, V+H

Glitch of an sunflower by kimasendorf mode 0

Sorted by mode 2, respectively glitch: H, H+V, V, V+H. This glitch was very discreet in this image and only affected the dark areas below the flower.

Glitch of an sunflower by kimasendorf mode 0

For a visual demonstration of this method, wacht this video:

Visualization on how kimasendorf / ASDFPixelSort glitches some Colorful Stripes img [1296x864]

Glitch by KrabCode Noise directed pixel sorting

Based on KrabCode Noise directed pixel sort. Just a few modifications to show original image in the corner, when reseting the image will have a fade effect and able to select image from local machine.

Sketch options can be controlled by keyboard keys:

  • 'k' -> save image at /capture/ folder
  • 'r' -> reset to original img
  • 'i' -> show smaller original image in the corner as a thumbnail
  • 'p' -> pause animation

Glitch of an sunflower by KrabCode Noise directed pixel sorting

For a visual demonstration of this method, wacht this video:

Let's melt this colorful cat img [900x853] using KrabCode Noise directed pixel sorting

Glitch by KrabCode Voronoi filter

Based on KrabCode Voronoi filter. This program gets the average colour bellow each Voronoi cell and colour it. But because of the so many checks, for an image of 600x600 pixels, it was getting a maximum of 1 frame/s. So, I added a quadtree system to find the Voronoi points faster and also tweaked the checking of pixels so only half the checks are necessary; this double the animation speed but that makes the Voronoi cell pixelated. No it can reach 15 frames/s for 500 Voronoi cells. Even with 1000 Voronoi cells I can get 12 frames/s with the right divider number (controls the scan area of the QuadTree). Before the quadtree and the less checking hacking, for 500 Voronoi points and 600x600 size, on every frame it was doing 180,000,000 checks and now with the implematetions and the optimum divisor for the QuadTree scan, it is doing around 700,000 checks. This is the effect:

Glitch of an sunflower by KrabCode Voronoi filter

I used the Coding train QuadTree template. The performance increase with the quadtree is gain because we only need to scan for a point in a small section of the image. I used a variable 'div' to divide the screen by that number and search the point at that location. It is important to notice that if the scan area is too small it might find no points in the area (and will start checking the entire image) and if it is too big, will need to check too many points unnecessarily. This makes the frame rate having a maximum optimum value with a single 'div' value that depends on the image screen size, number of Voronoi points and their distribution. I could write a opmimazer function that search dinamically for the best 'div' value, but let's not go crazy for a simple sketch. The main variable names are as follow:

  • boolean lessChecking = true; //increase speed animation by checking only half the pixel, but pixelates
  • boolean useQuadtree = true;
  • boolean showQuadtree = false; //show Quadtree structure and mouse hover can scan the voronoi points (useQuadtree MUST be true to show Quadtree)
  • boolean showBothIMGs = true; //to show both sources or only sorted source. Press 'i' for on|off
  • int div = 15; // Divides the screen in a small rectangle to search points using Quadtree
  • boolean showFrameRate = true;
  • boolean showOriginalsource = true; //allows to show original image for 2s at the start of animation
  • int pointCount = 500; //original 500 //How many points to create the Voronoi stuff
  • private int framesToCapture = 300; // to make gifs

Sketch options can be controlled by keyboard keys:

  • 'k' -> save image at /capture/ folder
  • 'i' -> show smaller original image in the corner as a thumbnail
  • 'p' -> pause animation
  • '+' -> increase size of divisor 'div' (makes the scan area smaller)
  • '-' -> decrease size of divisor 'div' (makes the scan area bigger)
  • 'c' -> Enable/Disable less checking on pixels to find Voronoi points
  • 's' -> show Quadtree structure and the mouse hover have a scan area to find Voronoi points
  • 'q' -> Enable/Disable the use of Quadtree system
  • 'f' -> show the frame rate in the upper part

For a visual demonstration of this method, wacht this video:

Visualization of KrabCode Voronoi filter on a colorful cat img [600x600]

                  o    .   _     .
                    .     (_)         o
             o      ____            _       o
            _   ,-/   /)))  .   o  (_)   .
           (_)  \_\  ( e(     O             _
           o       \/' _/   ,_ ,  o   o    (_)
            . O    _/ (_   / _/      .  ,        o
               o8o/    \\_/ / ,-.  ,oO8/( -TT
              o8o8O | } }  / /   \Oo8OOo8Oo||     O
             Oo(""o8"""""""""""""""8oo""""""")    
            _   `\`'                  `'   /'   o
           (_)    \                       /    _   .
                O  \           _         /    (_)
          o   .     `-. .----<(o)_--. .-'
             --------(_/------(_<_/--\_)--------hjw
        Eeeek! Can't you see I'm trying to take a bath?
        Go glitch some images and jUST come after all pixels are done.

- - -

[ all code available under MIT License - feel free to use. ]

For more resources for glitch stuff try the following libraries:

pixelglitch's People

Contributors

volfegan avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.