第08章imagej插件编程docx.docx
《第08章imagej插件编程docx.docx》由会员分享,可在线阅读,更多相关《第08章imagej插件编程docx.docx(8页珍藏版)》请在冰豆网上搜索。
第08章imagej插件编程docx
JAVA语言
第8章ImageJ插件编程
赵毅力
ylzhao@swfu.e
IMAGEJ
插件安装
新建插件
选择ImageJ的"Plugins"菜单中的"New"菜单选项。
插件类型
有三种插件类
型可以选择:
PluginFilter扌雨
PluginFrame
Plugin插件
件
■插件
不需要图像作为输入的插件可以实现Plugin接口。
Plugin接口的定义为:
•publicinterfacePlugin{
•publicvoidrun(Stringargs);
•}
—个实现Plugin接口的自定义插件:
•publicclassMy_PluginimplementsPlugin{
•publicvoidrun(Stringarg)(
•IJ.showMessage(,,My_Plugin,',"Helloworld!
");
•J
•}
需要对图像进行处理的插件可以实现PluglnFilter接口。
PluglnFilter接口的定义为:
•publicinterfacePluglnFilter{
•publicintsetup(Stringarg,ImagePlusimp);
•publicvoidrun(lmageProcessorip);•}
publicclassMy_Filter_PluginimplementsPluglnFilter{ImagePlusimp;
publicintsetup(Stringarg,ImagePlusimp){this.imp=imp;returnD0ES_8G;
}
publicvoidrun(ImageProcessorip){ImagePluscopy=newlmagePlus(ncopy,f,ip);copy.show();
i需要用户界面的插件可以继承PluglnFrame类。
PluglnFrame类的定义为:
kJ
•publicclassPluglnFrameextendsjava.awt.FrameimplementsPlugin{}
publicclassMy_Plugin_FrameextendsPluglnFrame{
Panelpanel;
publicMy_Plugin_Frame(){super("Plugin_Frame”);panel=newPanel();panel.setLayout(newGridLayout(l,3,5,5));addButton("Stepln);
addButtonfStep2”);addButton("Step3n);
add(panel);pack();GUI.center(this);setVisible(true);
1
privatevoidaddButton(Stringlabel){Buttonbtn=newButton(label);panel.add(btn);
ij.plugin.frame
图像类型
说明
字段名
8位灰度图像
雪个像素由byte类型表示z有256个灰度级。
GRAY8
8位彩色索引图像
每个像素的颜色由颜色查找表确定。
C0L0R.256
丄6位灰度图像
每个像素有65535个灰度级。
GRAY16
RGB彩色图像
每个像素由红、绿、蓝三个颜色分量组成,每个颜色分量取值为0-
255O
C0L0R.RGB
32位浮点图像
每个像素由float或者double类型的变量表示。
GRAY32
ImageJ
ImagePlus^^示
图像。
ImageProcessor类表示图像处理器。
ByteProcessor类
ShortProcessor类
ImageProcessor
AueuiSer
IMAGEPROCESSOR类
类的名称
含义
ByteProcessor
处理8位的灰度图像和彩色索引图像
ShortProcessor
处理16位的灰度图像
ColorProcessor
处理32位整数的彩色RGB图像
FloatProcessor
处理32位浮点数的灰度图像
BinaryProcessor
处理黑白图像
像素读写
读像素:
•publicabstractObjectgetPixels();
写像素:
•publicabstractvoidsetPixels(Objectpixels);
bytepix=pixelsfidx];//错误!
(灰度值范围为[0,255])
10000001
末位加久
40111mi)
idx
10000001
401111110)
10000001
intpix=pixels[idx]=)
idx
byte[]pixels=(byte[])ip.getPixels();//获取像素数组的引用intidx=10;
intpix=pixels[idx]&Oxff;
……//对Pix进行相应的处理
pix=255-pix;//取反
pixels[idx]=(byte)pix;//翕制类型转换
字节型
削妾舍弃高24位,只留
下低8位
shortilIS妲^^shorti师8對5禺曲融Mb牆謂鞠「弧1鹅
intidx=10;
intpix=pixels[idx]&?
?
?
?
;
……//对pix进行相应的处理
十进制
33068
pixels[idx]=(short)pix;//强制类型转换
111111*********1
1000000100101100
0000000000000000
ffffffff11111111
00000000000000001000000100101100
short[]
oooooooooooooooo
1000000100101100
削妾舍弃高16^,只留
下低16位
1000000100101100
■
intred=10;intgreen=100;
intblue=129;
00000000
00001010
01100100
10000001
AlphaiEfi
red通道
green通道
blueilil
RGB图像中的一个像素由32位整型组成
int[]MS(int⑴删耶切
intidx=10;
intred=(int)(pixels[i]&OxffOOOO)>>16;//获取红色分量
00000000
00001010
01100100
10000001
intgreen=(int)(pixels[i]&OxOOffOO)>>8;//获取绿色分量intblue=(int)(pixels[i]&OxOOOOff);//获取蓝色分量
00000000
mTnn
00000000
00000000
OxOOffOOOO
00000000
00001010
00000000
00000000
00000000
00000000
00000000
00001010
intred=(int)(pixels[i]&OxffOOOO)>>16;//获取红色分量intgreen=(int)(pixels[i]&OxOOffOO)>>8;//获取绿色分量intblue=(int)(pixels[i]&OxOOOOff);//获取蓝色分量……//连行相应处理
pixels[i]=(red&Oxff)«16)+((green&Oxff)«8)+(blue&Oxff);
00000000
00000000
00000000
00001010
&
00000000
00000000
00000000
iTiTmi
00000000
00000000
00000000
00001010
00000000
00001010
00000000
00000000
OxOOOOOOff
16