建立 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] )
);