All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.actelion.research.orbit.imageAnalysis.imaging.GBlur Maven / Gradle / Ivy

Go to download

Orbit, a versatile image analysis software for biological image-based quantification

There is a newer version: 3.15
Show newest version
/*
 *     Orbit, a versatile image analysis software for biological image-based quantification.
 *     Copyright (C) 2009 - 2017 Actelion Pharmaceuticals Ltd., Gewerbestrasse 16, CH-4123 Allschwil, Switzerland.
 *
 *     This program is free software: you can redistribute it and/or modify
 *     it under the terms of the GNU General Public License as published by
 *     the Free Software Foundation, either version 3 of the License, or
 *     (at your option) any later version.
 *
 *     This program is distributed in the hope that it will be useful,
 *     but WITHOUT ANY WARRANTY; without even the implied warranty of
 *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *     GNU General Public License for more details.
 *
 *     You should have received a copy of the GNU General Public License
 *     along with this program.  If not, see .
 *
 */

package com.actelion.research.orbit.imageAnalysis.imaging;

import javax.media.jai.PlanarImage;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.awt.image.DataBufferByte;
import java.awt.image.WritableRaster;

public class GBlur {

    public static PlanarImage adjustBlur(PlanarImage srcImg, final int b) {
        final int width = srcImg.getWidth();
        final int height = srcImg.getHeight();
        final int[] src = srcImg.getData().getPixels(0, 0, width, height, new int[width * height * 3]);
        final int[] dest = new int[width * height * 3];

        for (int l = 0; l < b; l++) {
            if (l == 0) {
                int dum;
                for (int i = 0; i < src.length - 3; i += 3) {
                    dum = src[i + 0];
                    src[i + 0] = src[i + 2];
                    src[i + 2] = dum;
                }
            } else {
                for (int i = 0; i < src.length - 3; i += 3) {
                    src[i + 0] = dest[i + 0];
                    src[i + 1] = dest[i + 1];
                    src[i + 2] = dest[i + 2];
                }
            }
            for (int i = width * 3 + 3; i < src.length - 3 - width * 3; i += 3) {
                dest[i + 0] = (src[i + 0] + src[i + 0 + 3] + src[i + 0 - 3] + src[i + 0 - width * 3] + src[i + 0 + 3 - width * 3] + src[i + 0 - 3 - width * 3] + src[i + 0 + width * 3] + src[i + 0 + 3 + width * 3] + src[i + 0 - 3 + width * 3]) / 9;
                dest[i + 1] = (src[i + 1] + src[i + 1 + 3] + src[i + 1 - 3] + src[i + 1 - width * 3] + src[i + 1 + 3 - width * 3] + src[i + 1 - 3 - width * 3] + src[i + 1 + width * 3] + src[i + 1 + 3 + width * 3] + src[i + 1 - 3 + width * 3]) / 9;
                dest[i + 2] = (src[i + 2] + src[i + 2 + 3] + src[i + 2 - 3] + src[i + 2 - width * 3] + src[i + 2 + 3 - width * 3] + src[i + 2 - 3 - width * 3] + src[i + 2 + width * 3] + src[i + 2 + 3 + width * 3] + src[i + 2 - 3 + width * 3]) / 9;
            }
        }

        DataBufferByte db = new DataBufferByte(dest.length);
        for (int i = 0; i < dest.length; i++) {
            db.setElem(i, dest[i]);
        }
        WritableRaster raster = WritableRaster.createWritableRaster(srcImg.getSampleModel(), db, new Point(0, 0));
        BufferedImage bi = new BufferedImage(srcImg.getColorModel(), raster, srcImg.getColorModel().isAlphaPremultiplied(), null);
        return PlanarImage.wrapRenderedImage(bi);
    }

    // GPU version using Aparapi - does not work properly...
    /*
    public static PlanarImage adjustBlurGPU(PlanarImage srcImg, final int b) {
		final int width = srcImg.getWidth();
		final int height = srcImg.getHeight();
		final int[] src = srcImg.getData().getPixels(0, 0, width, height, new int[width*height*3]);
		final int[] dest = new int[width*height*3];
		final int len = src.length;
		
		Kernel kernel = new Kernel() {
			@Override
			public void run() {
				int i = getGlobalId()*3;
				if (getPassId()==0) { // bgr -> rgb
					int dum = src[i+0];
					src[i+0] = src[i+2];
					src[i+2] = dum;
				} else
				if (getPassId()%2==1) { // blur
					if ((i>=width*3+3) && (i rgb
					int dum = src[i+0];
					src[i+0] = src[i+2];
					src[i+2] = dum;
				} else
				if ((i>=width*3+3) && (i




© 2015 - 2024 Weber Informatics LLC | Privacy Policy