创建 JMP 函数亲爱的大家,
我对 JMP 脚本的了解很少,而且 SAS 不允许我做我在 JMP 中可以做的图像处理方面的事情。
我对现有的 JMP 脚本进行了一些修改(约翰·庞特)允许我从图像生成 RGB 数据。
该脚本允许我对一张图像执行此操作,而我有 300 多张图像。
在 SAS 中,我很容易创建一个宏来自动执行此操作,但在 JMP 中则不然。
输入(图像)和输出(SAS 数据集)将具有相同的名称(红色的),这意味着该函数只有一个参数。
我想要处理的所有图像的名称都存储在 JMP 数据集(一列数据集)中。
这是脚本:
名称默认到这里(1);
// 将图像读入JMP
img = NewImage("D:\ M1_ACTIVE_ZL_T00 .jpg");
w = newWindow("图像", img);
// 获取 3 个不同矩阵(红色、绿色和蓝色)的像素值
// RGB 颜色位于标准化颜色空间 (0.0-1.0)
{r, g, b} = img << getPixels("rgb");
// 将 rgb 转换为灰度(强度)矩阵
我=0.3*r+0.59*g+0.11*b;
// 获取 JSL 颜色的像素值,然后转换为色调、亮度和饱和度
// HLS 颜色位于标准化颜色空间 (0.0-1.0)
jslColors = img << getPixels();
{h, l, s} = ColorToHLS(jslColors);
// 获取图像/矩阵的尺寸
行数 = nrow(r);
numCols = ncol(r);
// 创建数据表
dt = 新表("图像数据",
newColumn("X", 设置值(重复(1::numCols, numRows))),
newColumn("Y", 设置值(shape(repeat(1::numRows,numCols)`,numCols,numRows))),
newColumn("r", 设置值(r)),
newColumn("g", 设置值(g)),
newColumn("b", 设置值(b)),
newColumn("i", 设置值(i)),
newColumn("h", 设置值(h)),
newColumn("l", 设置值(l)),
newColumn("s", 设置值)
);
dt << 保存("D:\ M1_ACTIVE_ZL_T00 .sas7bdat");
关闭(dt);
img<<关闭窗口();
w<<关闭窗口();
预先感谢我们的帮助。
非常亲切的问候,
萨米尔
回复:创建 JMP 函数我会避免使用“j”作为变量,因为它也是一个 JSL 函数。 尝试用“k”代替。
J (nrows, , <值>)
描述:创建相同值的矩阵。
返回: 矩阵。
论据:
行数矩阵中的行数。 如果未指定 ncols,则 nrows 也用作 ncols。
恩科尔斯矩阵中的列数。
价值用于填充矩阵的值。 如果未指定值,则使用 1。
回复:创建 JMP 函数我很高兴您也发现了“i”变量问题。真正应该做的可能是将函数中的变量声明为函数的局部变量。这将解决问题而无需更改变量名称
ImageProcessing = Function( {ImagePath},
{img,w,i,r,g,b,h,l,s,numRows,numCols,dt},
回复:创建 JMP 函数谢谢吉姆,
现在可以了:)
但我也用 j 替换了 i 。
我不明白我为什么不工作。
祝你今天过得愉快,
萨米尔
回复:创建 JMP 函数我认为它只在一张图像后停止的原因是我错误地使用变量“dt”指向其中包含图像名称的数据表,并且在函数内部,它还使用了变量“dt”,它改变了这是价值。通过在函数内部本地化“dt”变量,或者仅更改函数外部的变量“dt”,可以轻松解决此问题。我选择了后者,在下面的示例中,我将其重命名为“dtimage”
Names Default To Here( 1 );
// Read the image into JMP M1_ACTIVE_ZL_T00
ImageProcessing = Function( {ImagePath},
img = New Image( "D:\" || ImagePath || ".jpg" );
w = New Window( "image", img );
// Get the pixel values as 3 distinct matrices (red, green and blue)
// RGB colors are in normalized color space (0.0-1.0)
{r, g, b} = img << getPixels( "rgb" );
// Convert rgb to gray-scale (intensity) matrix
i = 0.3 * r + 0.59 * g + 0.11 * b;
// Get the pixel values as JSL colors then convert to hue, lightness and saturation
// HLS colors are in normalized color space (0.0-1.0)
jslColors = img << getPixels();
{h, l, s} = Color To HLS( jslColors );
// Get the dimensions of the image/matrices
numRows = N Row( r );
numCols = N Col( r );
// Create a data table
dt = New Table( "Image Data",
New Column( "X", set values( Repeat( 1 :: numCols, numRows ) ) ),
New Column( "Y", set values( Shape( Repeat( 1 :: numRows, numCols )`, numCols, numRows ) ) ),
New Column( "r", set values( r ) ),
New Column( "g", set values( g ) ),
New Column( "b", set values( b ) ),
New Column( "i", set values( i ) ),
New Column( "h", set values( h ) ),
New Column( "l", set values( l ) ),
New Column( "s", set values( s ) )
);
dt << Save( "D:\" || ImagePath || ".sas7bdat" );
Close( dt, nosave );
img << close Window();
w << close Window();
);
dtimage = Open( "path to data table with the one column with image names" );
// We will pretend that the column name is "TheImage"
For( i = 1, i <= N Rows( dtimage ), i++,
return = ImageProcessing( dtimage:TheImage[i] )
);回复:创建 JMP 函数他,
是的,我在图像处理插件中看到了这个功能。
这是有用的。
克尔斯,
萨米尔
回复:创建 JMP 函数嗨克雷格,
非常感谢您的回答,我确信接下来的几天我会需要这个。
克尔斯,
萨米尔
回复:创建 JMP 函数亲爱的吉姆,
非常感谢您的代码,这正是我想要的。
唯一的问题是该函数仅执行我表的第一行。
你知道为什么吗?
当我说“小”时,我指的是我对 JMP 的了解,而不是 JMP 
v 预先感谢您的反馈。
萨米尔
回复:创建 JMP 函数一个相关的想法 - 如果您有一个多图像文件(即显微镜中常见的动画 GIF 或 TIF 堆栈),JMP 13(仅限 Windows 版本)将直接将它们加载为一个数据集。 如果您有连续图像数据,您可以考虑采用此路线并将图像打包到多图像文件中。 它还使您的图像档案的维护变得更加容易。
中号
回复:创建 JMP 函数以下是一些可能有帮助的想法。
dt = New Table( "Untitled",
Add Rows( 3 ),
New Column( "name",
Character,
"Nominal",
Set Selected,
Set Values( {"aaa", "bb", "cccc"} )
)
);
processFun = Function( {inputfile, outputfile},
{default local},
Show( inputfile, outputfile )
);
For( irow = 1, irow <= N Rows( dt ), irow++,
input = "c:/directory3/" || dt:name[irow] || ".jpg";
output = "c:/directory2/" || dt:name[irow] || ".png";
processFun( input, output );
);
/*:
inputfile = "c:/directory3/aaa.jpg";
outputfile = "c:/directory2/aaa.png";
inputfile = "c:/directory3/bb.jpg";
outputfile = "c:/directory2/bb.png";
inputfile = "c:/directory3/cccc.jpg";
outputfile = "c:/directory2/cccc.png";
该示例显示了一个具有两个参数的用户函数“processFun”,并显示了读取数据表的循环,并显示了一些字符串连接运算符来构建您需要的名称。
回复:创建 JMP 函数我承认,在 SAS 与 JMP 的相对范围内,SAS 是一个更大的系统,但我不能同意你的观点,即 JMP 很小。这是您的脚本,修改得很简单,应该可以完成您想要的操作。JMP 不必像 SAS 那样有单独的宏语言,因为 JMP(JSL) 的语言内置了代码生成等功能。
这是我想出的代码
Names Default To Here( 1 );
// Read the image into JMP M1_ACTIVE_ZL_T00
ImageProcessing = Function( {ImagePath},
img = New Image( "D:\" || ImagePath || ".jpg" );
w = New Window( "image", img );
// Get the pixel values as 3 distinct matrices (red, green and blue)
// RGB colors are in normalized color space (0.0-1.0)
{r, g, b} = img << getPixels( "rgb" );
// Convert rgb to gray-scale (intensity) matrix
i = 0.3 * r + 0.59 * g + 0.11 * b;
// Get the pixel values as JSL colors then convert to hue, lightness and saturation
// HLS colors are in normalized color space (0.0-1.0)
jslColors = img << getPixels();
{h, l, s} = Color To HLS( jslColors );
// Get the dimensions of the image/matrices
numRows = N Row( r );
numCols = N Col( r );
// Create a data table
dt = New Table( "Image Data",
New Column( "X", set values( Repeat( 1 :: numCols, numRows ) ) ),
New Column( "Y", set values( Shape( Repeat( 1 :: numRows, numCols )`, numCols, numRows ) ) ),
New Column( "r", set values( r ) ),
New Column( "g", set values( g ) ),
New Column( "b", set values( b ) ),
New Column( "i", set values( i ) ),
New Column( "h", set values( h ) ),
New Column( "l", set values( l ) ),
New Column( "s", set values( s ) )
);
dt << Save( "D:\" || ImagePath || ".sas7bdat" );
Close( dt, nosave );
img << close Window();
w << close Window();
);
dt = Open( "path to data table with the one column with image names" );
// We will pretend that the column name is "TheImage"
For( i = 1, i <= N Rows( dt ), i++,
return = ImageProcessing( dt:TheImage[i] )
);