ImageJ¤ÇPlug-in¤òºî¤ë»þ¤Î»²¹Í¤Ë¤Ê¤ì¤Ð¹¬¤¤¤Ç¤¹¡£
²èÁü½èÍýPlug-in¤Ï¡¢Interface ij.plugin.filter.PlugInFilter¤Î ¼ÂÁõ¤È¤·¤Æºî¤ê¤Þ¤¹¡£¤³¤³¤Ç¤Ï¤Þ¤º¡¢Test_¤È¤¤¤¦Plug-in¤ò ºî¤Ã¤Æ¤ß¤Þ¤¹¡£¤³¤Î¾ì¹ç¡¢¾¯¤Ê¤¯¤È¤â¼ÂÁõ¤¹¤ëɬÍפ¬¤¢¤ë¤Î¤Ï¡¢ void run(ImageProcessor ip)¤È int setup(java.lang.String arg, ImagePlus imp)¤Ç¤¹¡£ setup()¤Ï¡¢Plug-in Filter¤¬½èÍý¤Ç¤¤ë²èÁü¤Î¼ïÎà¤ò ÊÖ¤¹½é´ü´Ø¿ô¡¢run()¤Ï¡¢¼ÂºÝ¤Î½èÍý´Ø¿ô¤Ç¤¹¡£ ¾Ü¤·¤¯¤Ï¡¢API reference¤ò»²¾È¤·¤Æ²¼¤µ¤¤¡£ Plug-in¤Î̾Á°¤Ë¤Ï_¤¬´Þ¤Þ¤ì¤Æ¤¤¤ëɬÍפ¬¤¢¤ë¤è¤¦¤Ç¤¹¡£
import ij.*;
import ij.process.*;
import ij.gui.*;
import ij.plugin.filter.*;
public class Test_ implements PlugInFilter
{
public int setup(String arg, ImagePlus img)
{
if (IJ.versionLessThan("1.28e"))
return DONE;
else
// ¤É¤Î¼ïÎà¤Î²èÁü¤â°·¤¨¤ë¤·¡¢¥Þ¥ë¥Á¥Ú¡¼¥¸tiff
// ¤Ê¤É¤â°·¤¨¤ë¤³¤È¤ò¸À¤¦¡£
return DOES_ALL+DOES_STACKS;
}
public void run(ImageProcessor ip)
{
// Éý¤ò¼èÆÀ
int width = ip.getWidth();
// ¹â¤µ¤ò¼èÆÀ
int height = ip.getHeight();
int[] p1 = new int[3];
// load
for (int y=1; y<height; y++)
{
for (int x=0; x<width; x++)
{
// (x,y)¤ÎPixel¥Ç¡¼¥¿¤ò¼èÆÀ¡£
// int[] ¤Ï¡¢RGB¤Ç¤¢¤ë¡£
// !!!! Ãí°Õ !!!!
// °Ê¹ß¤ÎÎãÂê¤Ç¤Ï¤Û¤È¤ó¤É¤³¤ÎgetPixel¤ò»È¤Ã¤Æ¤¤¤Þ¤¹¤¬¡¢
// ¤³¤ì¤Ï¥×¥í¥°¥é¥à¤ò¸«¤ä¤¹¤¯¤¹¤ë¤¿¤á¤Ç¤¹¡£
// ²èÁü¤Î²èÁÇ¿ô¤À¤±¸Æ¤Ó½Ð¤¹¤Î¤Ç¡¢
// ¼ÂÍÑŪ¤Ç¤Ï¤¢¤ê¤Þ¤»¤ó¡£¼ÂºÝ¤Ë»È¤¦¾ì¹ç¤Ï¡¢
// getPixels¤Ê¤É¤ò»È¤Ã¤Æ¹â®²½¤·¤Æ¤¯¤À¤µ¤¤¡£
p1 = ip.getPixel(x, y, p1);
}
}
}
}
¤³¤ÎÆâÍÆ¤òTest_.java¤È¤¤¤¦Ì¾Á°¤Ç¡¢ ImageJ¤Î¥Ç¥£¥ì¥¯¥È¥ê¤ÎÃæ¤Îplugins¤È¤¤¤¦¥Ç¥£¥ì¥¯¥È¥ê¤Ë Êݸ¤·¤Æ¤¯¤À¤µ¤¤¡£
¥³¥ó¥Ñ¥¤¥ë¤¹¤ë»þ¤Ï¡¢°Ê²¼¤Î¤è¤¦¤Ë¤·¤Æ¡¢ImageJ¤Î¥é¥¤¥Ö¥é¥ê¤Î °ÌÃÖ¤òjavac¤Ë¶µ¤¨¤ëɬÍפ¬¤¢¤ê¤Þ¤¹¡£
¥³¥ó¥Ñ¥¤¥ë¤¬½ª¤Ã¤ÆTest_.class¤¬¤Ç¤¤ì¤Ð¡¢java -jar ij.jar¤Ê¤ê¤·¤Æ ImageJ¤ò¼Â¹Ô¤·¤Þ¤¹¡£°ìÈÖ±¦¤ÎPlugins¤È¤¤¤¦¥á¥Ë¥å¡¼¤ÎÃæ¤Ë Test¤È¤¤¤¦¹àÌܤ¬¤Ç¤¤Æ¤¤¤ë¤Ç¤·¤ç¤¦¡£¤½¤¦¤·¤¿¤é¡¢¤¢¤È¤Ï²èÁü¤ò³«¤¤¤Æ ¤½¤Î¹àÌܤòÁª¤Ö¤À¤±¤Ç¤¹¡£ ¾å¤ÎÎã¤Ç¤Ï¡¢²èÁü¤Î½Ä²£¤ò¼èÆÀ¤·¡¢1¤Ä1¤Ä¤ÎPixel¤ò ÆÉ¤à¤È¤¤¤¦Æ°ºî¤ò¤·¤Þ¤¹¡£²èÁü¤ÏÊѹ¹¤µ¤ì¤º¡¢¸«¤«¤±¾å¤Ï¤Ê¤Ë¤âµ¯¤¤Þ¤»¤ó¡£
¼¡¤Ï¡¢¤½¤ì¤¾¤ì¤Î²èÁǤËÂФ·¤ÆFilter¤ò¤«¤±¤Æ¤ß¤Þ¤·¤ç¤¦¡£¤³¤³¤Ç¤Ï¡¢ ¤½¤ì¤¾¤ì¤Î²èÁǤËÂФ·¡¢¤½¤³¤¬ÌÀ¤ë¤µ¤Ç200¤è¤ê¾®¤µ¤±¤ì¤Ð ¹õ¤¯¡¢¤½¤ì°Ê³°¤Ï¤½¤Î¤Þ¤Þ¤È¤¤¤¦¤â¤Î¤òºî¤Ã¤Æ¤ß¤Þ¤¹¡£º£Å٤ϡ¢Test2_.java ¤È¤¤¤¦Ì¾Á°¤Ë¤·¤Æ²¼¤µ¤¤¡£
import ij.*;
import ij.process.*;
import ij.gui.*;
import ij.plugin.filter.*;
public class Test2_ implements PlugInFilter
{
// ÌÀ¤ë¤µ Y = 0.299R+0.587G+0.114B
// ¿§º¹ Cr = 0.500R-0.419G-0.081B
// ¿§º¹ Cb = -0.169R-0.332G+0.500B
// ²èÁǤ«¤éÌÀ¤ë¤µ¤ò·×»»
private double getY(int[] a)
{
if (a.length != 3)
return 0;
return 0.299*((double)a[0])+0.587*((double)a[1])+0.114*((double)a[2]);
}
public int setup(String arg, ImagePlus img)
{
if (IJ.versionLessThan("1.28e"))
return DONE;
else
// ¤É¤Î¼ïÎà¤Î²èÁü¤â°·¤¨¤ë¤·¡¢¥Þ¥ë¥Á¥Ú¡¼¥¸tiff
// ¤Ê¤É¤â°·¤¨¤ë¤³¤È¤ò¸À¤¦¡£
return DOES_ALL+DOES_STACKS;
}
public void run(ImageProcessor ip)
{
// Éý¤ò¼èÆÀ
int width = ip.getWidth();
// ¹â¤µ¤ò¼èÆÀ
int height = ip.getHeight();
int[] p1 = new int[3];
int[] black = {0, 0, 0};
// load
for (int y=1; y<height; y++)
{
for (int x=0; x<width; x++)
{
// (x,y)¤ÎPixel¥Ç¡¼¥¿¤ò¼èÆÀ¡£
// int[] ¤Ï¡¢RGB¤Ç¤¢¤ë¡£
p1 = ip.getPixel(x, y, p1);
// ÌÀ¤ë¤µ¤¬100¤è¤ê¾®¤µ¤±¤ì¤Ð¹õ¤Ë¤·¤Æ¤·¤Þ¤¦¡£
if (getY(p1) < 100)
ip.putPixel(x, y, black);
}
}
}
}
¤³¤³¤Ç¤Ï¡¢putPixel¤È¤¤¤¦´Ø¿ô¤Ç½ÐÎϤ·¤Æ¤¤¤Þ¤¹¡£
º£Å٤ϡ¢²èÁü¤ËÂФ·¡¢·×¬¤ò¹Ô¤Ê¤Ã¤Æ¤½¤Î·ë²Ì¤òɽ¤Ç½ÐÎÏ ¤¹¤ë¤â¤Î¤ò¹Í¤¨¤Æ¤ß¤Þ¤·¤ç¤¦¡£
import ij.*;
import ij.process.*;
import ij.gui.*;
import ij.plugin.filter.*;
public class Test3_ implements PlugInFilter
{
// ÌÀ¤ë¤µ Y = 0.299R+0.587G+0.114B
// ¿§º¹ Cr = 0.500R-0.419G-0.081B
// ¿§º¹ Cb = -0.169R-0.332G+0.500B
// ²èÁǤ«¤éÌÀ¤ë¤µ¤ò·×»»
private double getY(int[] a)
{
if (a.length != 3)
return 0;
return 0.299*((double)a[0])+0.587*((double)a[1])+0.114*((double)a[2]);
}
public int setup(String arg, ImagePlus img)
{
if (IJ.versionLessThan("1.28e"))
return DONE;
else
// ¤É¤Î¼ïÎà¤Î²èÁü¤â°·¤¨¤ë¤·¡¢¥Þ¥ë¥Á¥Ú¡¼¥¸tiff
// ¤Ê¤É¤â°·¤¨¤ë¤³¤È¤ò¸À¤¦¡£
return DOES_ALL+DOES_STACKS;
}
public void run(ImageProcessor ip)
{
// Éý¤ò¼èÆÀ
int width = ip.getWidth();
// ¹â¤µ¤ò¼èÆÀ
int height = ip.getHeight();
int[] p1 = new int[3];
// ɽ¤Îsetup
// Î㤨¤Ð¡¢°ì¹Ô¤Ë£³¤Ä¤Î»ö¹à¤ò½ÐÎϤ¹¤ë¤Ê¤é¡¢
// 1 \t 2 \t 3¤È¡¢£³¤Ä¤Î¥¿¥¤¥È¥ë¤ò\t¤Ç¶èÀڤäƽñ¤¯¡£
IJ.setColumnHeadings("x\t y\t bright");
// load
for (int y=1; y<height; y++)
{
for (int x=0; x<width; x++)
{
// (x,y)¤ÎPixel¥Ç¡¼¥¿¤ò¼èÆÀ¡£
// int[] ¤Ï¡¢RGB¤Ç¤¢¤ë¡£
p1 = ip.getPixel(x, y, p1);
// ÌÀ¤ë¤µ¤¬500¤è¤ê¾®¤µ¤±¤ì¤Ð¡¢
// ¾ì½ê¤ÈÌÀ¤ë¤µ¤òɽ¤Ë½ÐÎÏ
// ½ÐÎÏÊýË¡¤Ï¤µ¤Ã¤¤ÈƱ¤¸¤è¤¦¤Ë\t¤Ç¶èÀÚ¤ë
if (getY(p1) < 500)
IJ.write(x + "\t" + y + "\t" + getY(p1));
}
}
}
}
Àè¤Û¤É¤ÎÎã¤Ç¤¤¤¨¤Ð¡¢ÌÀ¤ë¤µ¤¬¤É¤ÎÃͤè¤êÂ礤¤¤Î¤«¤ò ¼Â¹ÔËè¤Ë»ØÄê¤Ç¤¤ë¤è¤¦¤Ë¤·¤Æ¤ß¤Þ¤·¤ç¤¦¡£¤³¤ì¤Ë¤Ï GenericDialog¤ò»ÈÍѤ·¤Þ¤¹¡£
import ij.*;
import ij.process.*;
import ij.gui.*;
import ij.plugin.filter.*;
public class Test4_ implements PlugInFilter
{
// ÌÀ¤ë¤µ Y = 0.299R+0.587G+0.114B
// ¿§º¹ Cr = 0.500R-0.419G-0.081B
// ¿§º¹ Cb = -0.169R-0.332G+0.500B
// ²èÁǤ«¤éÌÀ¤ë¤µ¤ò·×»»
private double getY(int[] a)
{
if (a.length != 3)
return 0;
return 0.299*((double)a[0])+0.587*((double)a[1])+0.114*((double)a[2]);
}
public int setup(String arg, ImagePlus img)
{
if (IJ.versionLessThan("1.28e"))
return DONE;
else
// ¤É¤Î¼ïÎà¤Î²èÁü¤â°·¤¨¤ë¤·¡¢¥Þ¥ë¥Á¥Ú¡¼¥¸tiff
// ¤Ê¤É¤â°·¤¨¤ë¤³¤È¤ò¸À¤¦¡£
return DOES_ALL+DOES_STACKS;
}
public void run(ImageProcessor ip)
{
// dialog¤Îɽ¼¨¡£¥¥ã¥ó¥»¥ë¤Ç¤½¤Î¤Þ¤ÞÌá¤ë¡£
if(getParam())
return ;
// Éý¤ò¼èÆÀ
int width = ip.getWidth();
// ¹â¤µ¤ò¼èÆÀ
int height = ip.getHeight();
int[] p1 = new int[3];
int[] black = new int[3];
black[0] = 0; black[1] = 0; black[2] = 0;
// ɽ¤Îsetup
// Î㤨¤Ð¡¢°ì¹Ô¤Ë£³¤Ä¤Î»ö¹à¤ò½ÐÎϤ¹¤ë¤Ê¤é¡¢
// 1 \t 2 \t 3¤È¡¢£³¤Ä¤Î¥¿¥¤¥È¥ë¤ò\t¤Ç¶èÀڤäƽñ¤¯¡£
IJ.setColumnHeadings("x\t y\t bright");
// load
for (int y=1; y<height; y++)
{
for (int x=0; x<width; x++)
{
// (x,y)¤ÎPixel¥Ç¡¼¥¿¤ò¼èÆÀ¡£
// int[] ¤Ï¡¢RGB¤Ç¤¢¤ë¡£
p1 = ip.getPixel(x, y, p1);
// ÌÀ¤ë¤µ¤¬50¤è¤ê¾®¤µ¤±¤ì¤Ð¡¢
// ¾ì½ê¤ÈÌÀ¤ë¤µ¤òɽ¤Ë½ÐÎÏ
// ½ÐÎÏÊýË¡¤Ï¤µ¤Ã¤¤ÈƱ¤¸¤è¤¦¤Ë\t¤Ç¶èÀÚ¤ë
if (getY(p1) < brightLimit)
IJ.write(x + "\t" + y + "\t" + getY(p1));
// ¤â¤·²èÁüÊѹ¹¤¬µö²Ä¤µ¤ì¤Æ¤¤¤ì¤Ð
// ¾ò·ï¤Ë¹ç¤ï¤Ê¤¤¤È¤³¤í¤ò¹õ¤ÇÅɤê¤Ä¤Ö¤¹
else if (ifChange)
ip.putPixel(x, y, black);
}
}
}
// static¤Ë¤·¤Æ¤ª¤¯¤È¡¢¼¡¤ËPlug-in¤ò¼Â¹Ô¤·¤¿»þ¤â
// °ÊÁ°¤ÎÆþÎÏ·ë²Ì¤¬Êݸ¤µ¤ì¤Æ¤¤¤ë¡£
static int brightLimit = 50;
// static ¤Ç¤Ê¤±¤ì¤Ð¼Â¹ÔËè¤Ë½é´ü²½¤µ¤ì¤Þ¤¹¡£
private boolean ifChange = false;
// ¤³¤³¤Ç¥æ¡¼¥¶¤«¤éParameter¤ò¼èÆÀ¡£
// ¼Â¹ÔÁ°¤Ëdialog¤¬½Ð¤Þ¤¹¡£
private boolean getParam()
{
GenericDialog gd = new GenericDialog("Enter Parameters.",
IJ.getInstance());
gd.addNumericField("", brightLimit, 0);
gd.addCheckbox("change image", ifChange);
// Ʊ¤¸¤è¤¦¤Ë¤·¤ÆÂ¾¤ÎParameter¤â¼èÆÀ¤Ç¤¤Þ¤¹¡£
// dialogɽ¼¨
gd.showDialog();
// dialog¤Ç¥¥ã¥ó¥»¥ë¥Ü¥¿¥ó¤¬²¡¤µ¤ì¤¿»þ
// ¡Ê¤Á¤ç¤Ã¤È±ø¤¤½èÍý¤Î»ÅÊý¤Ç¤¹¡£Java¤é¤·¤¯¤¹¤ë¤Ê¤éÎã³°¤ò»È¤¦¤Î¤«¤Ê¡£¡Ë
if (gd.wasCanceled())
{
return true;
}
// ¤³¤³¤Ç¼èÆÀ·ë²Ì¤òÂåÆþ¡£¾Ü¤·¤¯¤ÏAPI doc¤ò»²¾È¤·¤Æ²¼¤µ¤¤¡£
brightLimit = (int) gd.getNextNumber();
ifChange = (boolean) gd.getNextBoolean();
// ¾¤ÎParameter¤â¤³¤³¤Ç¼èÆÀ²Äǽ¤Ç¤¹¡£
return false;
}
}
¤ª¤½¤é¤¯¼Â¹Ô¤¹¤ì¤Ð¾å¤Î¤è¤¦¤Êdialog¤¬¸½¤ì¤ë¤Ç¤·¤ç¤¦¡£ Change image¤Ë¥Á¥§¥Ã¥¯¤ò¤Ä¤±¤Æ¼Â¹Ô¤¹¤ì¤Ð²èÁü¤¬Êѹ¹¤µ¤ì¡¢ ¤½¤¦¤Ç¤Ê¤±¤ì¤Ðñ¤Ë·×¬¤¬¹Ô¤Ê¤ï¤ì¤Þ¤¹¡£
¾¤Ë¤â¿§¡¹¤Ê´Ø¿ô¤¬Â¸ºß¤¹¤ë¤Î¤Ç¡¢API¤ò¸«¤Æ»î¤·¤Æ¤ß¤Æ²¼¤µ¤¤¡£
Imagine that you went to Mars, where you discovered that the beings who live
there don’t have the portable music player. They’re still using boom boxes.
You realize this is a huge business opportunity and start selling portable MP3
players (except on Mars they’re called Qxyzrhjjjjukltks) and compatible
headphones. To connect the MP3 player to the headphones, you invent a neat
kind of metal jack that looks like this:
Picture of a stereo headphone jackBecause you control the player and the
headphone, you can ensure that your player works with your headphones. This is
a ONE TO ONE market. One player, one headphone.
-- Joel Spolsky
-- "Martian Headsets" ( http://www.joelonsoftware.com/items/2008/03/17.html )
"You have been in Afghanistan, I perceive."
-- Sir Arthur Conan Doyle, "A Study in Scarlet"