自迁移出 MediaWiki 以来,本页内容尚未经过审查。如果您愿意帮忙,请查看帮助指南!
Natively, ImageJ supports RGB and HSL color spaces. There is no effort spent to support RGB because the application is targeted at scientific image processing rather than image preparation for screen or print. For pure educational purposes, we show here how to do a trivial transformation between uncalibrated linear color management to uncalibrated linear subtractive where, in RGB, the grey intensity is just (R+G+B)/3.
说明
CMYK 是一种CMYK色彩空间,具有灰色通道以节省色彩墨水。纯青色、黄色和洋红色的数量通过线性组合 RGB 数量来计算(在无符号字节范围 [0…255] 中):
c = 1 - r / 255
m = 1 - g / 255
y = 1 - b / 255
然后分离纯灰色总量:
k = min( c, y, k )
if ( k == 1 )
c = m = y = 0
else
s = 1 - k
c = ( c - k ) / s
m = ( m - k ) / s
y = ( y - k ) / s
即,至少一个CMY通道始终为零。
代码
这是 BeanShell,可以通过 Script Editor 或 BeanShell Interpreter 执行,或者将其作为扩展名为 .bsh 的文件拖到斐济工具即可执行。该脚本以解释的语言执行每个像素操作,因此速度非常慢。如果您确实需要更快的速度,则相关源代码编译为 Java 类,这对于 BeanShell 代码来说是直接的。
import ij.*;
import ij.process.*;
ipRGB = IJ.getImage().getProcessor();
/* CMYK */
ipC = new FloatProcessor( ipRGB.getWidth(), ipRGB.getHeight() );
ipM = new FloatProcessor( ipRGB.getWidth(), ipRGB.getHeight() );
ipY = new FloatProcessor( ipRGB.getWidth(), ipRGB.getHeight() );
ipK = new FloatProcessor( ipRGB.getWidth(), ipRGB.getHeight() );
/* CMYK visualized as RGB images */
ipCVis = new ColorProcessor( ipRGB.getWidth(), ipRGB.getHeight() );
ipMVis = new ColorProcessor( ipRGB.getWidth(), ipRGB.getHeight() );
ipYVis = new ColorProcessor( ipRGB.getWidth(), ipRGB.getHeight() );
ipKVis = new ColorProcessor( ipRGB.getWidth(), ipRGB.getHeight() );
pixels = ( int[] )ipRGB.getPixels();
cPixels = ( float[] )ipC.getPixels();
mPixels = ( float[] )ipM.getPixels();
yPixels = ( float[] )ipY.getPixels();
kPixels = ( float[] )ipK.getPixels();
cVisPixels = ( int[] )ipCVis.getPixels();
mVisPixels = ( int[] )ipMVis.getPixels();
yVisPixels = ( int[] )ipYVis.getPixels();
kVisPixels = ( int[] )ipKVis.getPixels();
for ( int i = 0; i < pixels.length; ++i ){
final int argb = pixels[ i ];
final float r = ( argb >> 16 ) & 0xff;
final float g = ( argb >> 8 ) & 0xff;
final float b = argb & 0xff;
final float c = 1.0f - r / 255.0f;
final float m = 1.0f - g / 255.0f;
final float y = 1.0f - b / 255.0f;
final float k = Math.min( c, Math.min( m, y ) );
if ( k >= 1.0f )
cPixels[ i ] = mPixels[ i ] = yPixels[ i ] = 0;
else {
final float s = 1.0f - k;
cPixels[ i ] = ( c - k ) / s;
mPixels[ i ] = ( m - k ) / s;
yPixels[ i ] = ( y - k ) / s;
}
kPixels[ i ] = k;
final int cVis = 255 - Math.round( cPixels[ i ] * 255.0f );
final int mVis = 255 - Math.round( mPixels[ i ] * 255.0f );
final int yVis = 255 - Math.round( yPixels[ i ] * 255.0f );
final int kVis = 255 - Math.round( kPixels[ i ] * 255.0f );
cVisPixels[ i ] = ( cVis << 16 ) | 0xffff;
mVisPixels[ i ] = ( mVis << 8 ) | 0xff00ff;
yVisPixels[ i ] = yVis | 0xffff00;
kVisPixels[ i ] = ( kVis << 16 ) | ( kVis << 8 ) | kVis;
}
ipC.setMinAndMax( 0.0, 1.0 );
ipM.setMinAndMax( 0.0, 1.0 );
ipY.setMinAndMax( 0.0, 1.0 );
ipK.setMinAndMax( 0.0, 1.0 );
new ImagePlus( "C", ipC ).show();
new ImagePlus( "M", ipM ).show();
new ImagePlus( "Y", ipY ).show();
new ImagePlus( "K", ipK ).show();
new ImagePlus( "C visualized", ipCVis ).show();
new ImagePlus( "M visualized", ipMVis ).show();
new ImagePlus( "Y visualized", ipYVis ).show();
new ImagePlus( "K visualized", ipKVis ).show();