Commit b210a2f1 authored by Johannes Schindelin's avatar Johannes Schindelin

Initial version

Signed-off-by: 's avatarJohannes Schindelin <johannes.schindelin@gmx.de>
parents
/target/
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.scijava</groupId>
<artifactId>pom-scijava</artifactId>
<version>1.19</version>
</parent>
<groupId>sc.fiji</groupId>
<artifactId>Process_Pixels</artifactId>
<version>1.0.0</version>
<name>plugins/Process_Pixels.jar</name>
<description>A Maven project implementing an ImageJ 1.x plugin</description>
<dependencies>
<dependency>
<groupId>net.imagej</groupId>
<artifactId>ij</artifactId>
<version>${imagej1.version}</version>
</dependency>
</dependencies>
</project>
import ij.IJ;
import ij.ImagePlus;
import ij.gui.GenericDialog;
import ij.plugin.filter.PlugInFilter;
import ij.process.ImageProcessor;
/**
* ProcessPixels
*
* A template for processing each pixel of either
* GRAY8, GRAY16, GRAY32 or COLOR_RGB images.
*
* @author The Fiji Team
*/
public class Process_Pixels implements PlugInFilter {
protected ImagePlus image;
// image property members
private int width;
private int height;
// plugin parameters
public double value;
public String name;
/**
* @see ij.plugin.filter.PlugInFilter#setup(java.lang.String, ij.ImagePlus)
*/
@Override
public int setup(String arg, ImagePlus imp) {
if (arg.equals("about")) {
showAbout();
return DONE;
}
image = imp;
return DOES_8G | DOES_16 | DOES_32 | DOES_RGB;
}
/**
* @see ij.plugin.filter.PlugInFilter#run(ij.process.ImageProcessor)
*/
@Override
public void run(ImageProcessor ip) {
// get width and height
width = ip.getWidth();
height = ip.getHeight();
if (showDialog()) {
process(ip);
image.updateAndDraw();
}
}
private boolean showDialog() {
GenericDialog gd = new GenericDialog("Process pixels");
// default value is 0.00, 2 digits right of the decimal point
gd.addNumericField("value", 0.00, 2);
gd.addStringField("name", "John");
gd.showDialog();
if (gd.wasCanceled())
return false;
// get entered values
value = gd.getNextNumber();
name = gd.getNextString();
return true;
}
/**
* Process an image.
*
* Please provide this method even if {@link ij.plugin.filter.PlugInFilter} does require it;
* the method {@link ij.plugin.filter.PlugInFilter#run(ij.process.ImageProcessor)} can only
* handle 2-dimensional data.
*
* If your plugin does not change the pixels in-place, make this method return the results and
* change the {@link #setup(java.lang.String, ij.ImagePlus)} method to return also the
* <i>DOES_NOTHING</i> flag.
*
* @param image the image (possible multi-dimensional)
*/
public void process(ImagePlus image) {
// slice numbers start with 1 for historical reasons
for (int i = 1; i <= image.getStackSize(); i++)
process(image.getStack().getProcessor(i));
}
// Select processing method depending on image type
public void process(ImageProcessor ip) {
int type = image.getType();
if (type == ImagePlus.GRAY8)
process( (byte[]) ip.getPixels() );
else if (type == ImagePlus.GRAY16)
process( (short[]) ip.getPixels() );
else if (type == ImagePlus.GRAY32)
process( (float[]) ip.getPixels() );
else if (type == ImagePlus.COLOR_RGB)
process( (int[]) ip.getPixels() );
else {
throw new RuntimeException("not supported");
}
}
// processing of GRAY8 images
public void process(byte[] pixels) {
for (int y=0; y < height; y++) {
for (int x=0; x < width; x++) {
// process each pixel of the line
// example: add 'number' to each pixel
pixels[x + y * width] += (byte)value;
}
}
}
// processing of GRAY16 images
public void process(short[] pixels) {
for (int y=0; y < height; y++) {
for (int x=0; x < width; x++) {
// process each pixel of the line
// example: add 'number' to each pixel
pixels[x + y * width] += (short)value;
}
}
}
// processing of GRAY32 images
public void process(float[] pixels) {
for (int y=0; y < height; y++) {
for (int x=0; x < width; x++) {
// process each pixel of the line
// example: add 'number' to each pixel
pixels[x + y * width] += (float)value;
}
}
}
// processing of COLOR_RGB images
public void process(int[] pixels) {
for (int y=0; y < height; y++) {
for (int x=0; x < width; x++) {
// process each pixel of the line
// example: add 'number' to each pixel
pixels[x + y * width] += (int)value;
}
}
}
void showAbout() {
IJ.showMessage("ProcessPixels",
"a template for processing each pixel of an image"
);
}
}
# Name: Process Pixels
# Author: The Fiji Team
# Version: 1.0.0
# A single .jar file can contain multiple plugins, specified in separate lines.
#
# The format is: <menu>, "<menu label>", <class name>
#
# If something like ("<arg>") is appended to the class name, the setup() method
# will get that as arg parameter; otherwise arg is simply the empty string.
Process, "Process Pixels", Process_Pixels
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment