2025年8月20日

imagej課程:binary mask image,label image與ROI的轉換

binary 8-bit image

  1. binary image -> ROI manager

    1. 執行Edit › Selection › Create Selection可將binary mask image 轉成selection
    2. 在ROI manager按add加入
  2. binary image -> label image

    1. Analyze › Analyse Particles show勾選Count Mask就會產生Labeled 16-bit image,每個區塊為一個獨特的數字。(此部份可以參考 特徵擷取最後的show說明)。或者使用Plugins › MorphoLibJ › Binary Images › Connected Components Labeling(但要先安裝IJPB)。
    2. 調整顯示顏色
      1. Image > Lookup Table > glasbey_on_dark可以改變成相近區塊有明顯差異的顏色
      2. Plugins › MorphoLibJ › Label Images › Set Label Map也可以shuffle顏色。

label 16-bit image

  1. label image -> binary image
    1. 轉8-bit
    2. 使用Image > Adjust > Threshold擷取需要的區塊。
  2. label image -> roi manager
    1. 將具有Labels的label image 轉入 ROI manager。執行Plugins › MorphoLibJ › Label Images › Label Map to ROIs

ROI manager

  1. ROI manager -> binary image

    1. 在ROI manger選擇ROI後,執行Edit › Selection › Create Mask,即可轉成binary mask image。
  2. ROI manager -> label image
    使用Macro將ROI轉成隨機顯示顏色的label image


// 取得影像大小
width = getWidth();
height = getHeight();

// 建立空白的 16-bit Labeled Image
newImage("Labeled Image", "16-bit black", width, height, 1);
setBatchMode("hide");

// 紀錄 ROI 數量
roiCount = roiManager("count");

// 把每個 ROI 畫上不同的灰階值
for (i = 0; i < roiCount; i++) {
    selectImage("Labeled Image");
    roiManager("select", i);
    setColor(i + 1); // 灰階值從 1 開始
    run("Fill", "slice");
}
setMinAndMax(0, 255);

run("glasbey_on_dark");

// 顯示完成訊息
setBatchMode("show");