Skip to content

Instantly share code, notes, and snippets.

View hageldave's full-sized avatar

David Hägele hageldave

  • University of Stuttgart
  • Germany / Stuttgart
View GitHub Profile
@hageldave
hageldave / RadonTransform.java
Last active March 22, 2019 00:39
RGB Radon Transform of Images
package radon;
import java.util.function.DoubleBinaryOperator;
import hageldave.imagingkit.core.Img;
import hageldave.imagingkit.core.io.ImageLoader;
import hageldave.imagingkit.core.io.ImageSaver;
import hageldave.imagingkit.core.scientific.ColorImg;
import hageldave.imagingkit.core.util.ImageFrame;
@hageldave
hageldave / CriticalRegion.java
Created February 4, 2019 12:49
Semaphore with guaranteed release (even in case of exception) leveraging try with resources
import java.util.concurrent.Semaphore;
import java.util.concurrent.atomic.AtomicBoolean;
/**
* This class is a utility class for exception safe usage of a semaphore.
* When returns {@code semaphore.acquire() } the current thread successfully entered the
* critical region but it has to call {@code semaphore.release() } on exit to make room
* for other threads to enter the critical region.
* If this call is not guaranteed, thread starvation can occur (or even deadlock) since
package ezLinalg;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;
import java.util.function.BiFunction;
import java.util.function.BinaryOperator;
import java.util.function.DoubleBinaryOperator;
@hageldave
hageldave / Radon Transform and FBP
Last active July 14, 2017 13:48
my first implementation of a radon transformation and filtered back projection
package hageldave.imagingkit.core;
import java.awt.BasicStroke;
import java.awt.Color;
import java.util.Arrays;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Consumer;
import java.util.function.DoubleFunction;
@hageldave
hageldave / Save Load raw bytes (Img)
Created April 24, 2017 21:15
loads and saves image data from and to a byte array
private static byte[] saveImgToBytes(Img img) {
int w = img.getWidth();
int h = img.getHeight();
int n = img.numValues();
int length = n*4 + 4+4;
byte[] b = new byte[length];
// save width
int i = 0;
b[i++] = signedByteToByte(w);
b[i++] = signedByteToByte(w>>8);
@hageldave
hageldave / strange directional blur
Created April 24, 2017 12:49
using the deviation from a direction vector the weight for pixels weight is determined
import hageldave.imagingkit.core.ImageLoader;
import hageldave.imagingkit.core.Img;
import hageldave.imagingkit.core.util.ImageFrame;
import hageldave.imagingkit.filter.implementations.ConvolutionFilter;
public class testmain {
public static void main(String[] args) throws InterruptedException {
Img img = ImageLoader.loadImgFromURL("http://www.wellcomeimageawards.org/WI-6561.24_WIA_2017_PP_holding_screen.jpg");
ConvolutionFilter c = new ConvolutionFilter();
float[] kernel = new float[17*17];
@hageldave
hageldave / GenericNative CodeGen
Last active January 31, 2017 16:51
Code generator for generating extra methods for native types based on generic template
package misc;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@hageldave
hageldave / Slices in Java
Last active January 21, 2017 14:42
wrapper for arrays
package misc;
import java.util.Arrays;
import java.util.Iterator;
import java.util.Spliterator;
import java.util.function.Consumer;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
public class Slice<T> implements Iterable<Slice.ArrayAccessor<T>>{
@hageldave
hageldave / Pixel with cached x,y (not beneficial)
Created January 18, 2017 15:49
performance test for Pixel with cached x,y values using a box blur with large neighbourhood (51x51 ~ 2600 calls to getX,getY per pixel)
public static void main(String[] args) {
Img img1 = new Img(4000, 4000);
Img img2 = new Img(4000, 4000) {
@Override
public Pixel getPixel() {
return new Pixol(this, 0);
}
@hageldave
hageldave / converted pixel streaming
Last active December 22, 2016 23:46
convert pixel to anything else e.g float[] and stream it
public static void main(String[] args) {
Img img = new Img(200,200);
img.fill(0xff000000);
Spliterator<float[]> split = new ConvertedPixelSpliterator<>(
img.spliterator(),
()->{return new float[6];},
testmain::pixel2vec,
testmain::vec2Pixel);