前幾天看到網路上流傳了一個在灰階影像上加上彩色線條之後,看起來就好像是彩色圖片的視覺效果,我看了覺得很有趣,很想自己來動手玩一玩。於是就用imagej玩看看,順便寫了一個code script放在文章底下,有興趣的可以複製貼上玩玩看。
可以做什麼效果呢?可以針對個別區域製作橫紋效果。下面組圖是用同樣粗細的線寬,但是不同的線距
以下就是imagej的macro囉
===========================
lineW = 2;
space = 8;
angle = 0;
run("Select None");
rename("color");
run("Duplicate...", "title=grey");
selectWindow("grey");
run("8-bit");
run("RGB Color");
run("Set Measurements...", "area bounding redirect=None decimal=3");
roiManager("Select", 0);
run("Rotate...", "angle="+ angle +"");
roiManager("Add");
run("To Bounding Box");
run("Measure");
BX = getResult("BX", nResults-1);
BY = getResult("BY", nResults-1);
Width = getResult("Width", nResults-1);
Height = getResult("Height", nResults-1);
lineN = floor(Height/(lineW+space));
print(lineN);
for (i = 0; i < lineN; i++) {
//建立選取區
run("Specify...", "width="+ Width +" height="+ lineW +" x="+ BX +" y="+ BY+(space+lineW)*i +"");
//run("Rotate...", "angle="+ angle +"");
roiManager("Add");
//交集運算
roiManager("Select", newArray(1,roiManager("count")-1));
roiManager("AND");
//產生要繪圖的選取區ROI
roiManager("Add");
roiManager("deselect")
roiManager("Select", roiManager("count")-2);
roiManager("Delete");
//roiManager("Select", roiManager("count")-1);
//roiManager("Delete");
}
a1 = newArray(roiManager("count")-2);
for (i=0; i<a1.length; i++)
a1[i] = i+2;
roiManager("Select", a1);
roiManager("Combine");
roiManager("Add");
a1 = newArray(roiManager("count")-2);
for (i=0; i<a1.length; i++)
a1[i] = i+1;
roiManager("Select", a1);
roiManager("Delete");
roiManager("Select",roiManager("count")-1);
run("Rotate...", "angle="+ -angle +"");
roiManager("Add");
//====複製原圖,貼到黑白圖====
selectWindow("color");
roiManager("Select", roiManager("count")-1);
run("Copy");
selectWindow("grey");
roiManager("Select", roiManager("count")-1);
run("Paste");
//=========================
roiManager("Select", newArray(roiManager("count")-1,roiManager("count")-2));
roiManager("Delete");
selectWindow("color");
run("Select None");
selectWindow("grey");
run("Select None");
rename(lineW+":"+space);
text = "w"+lineW+":space"+space;
setFont("SansSerif", 14, " antialiased");
makeText(text, 20, getHeight()-20);
run("Add Selection...", "stroke=yellow fill=#660000ff new");
run("Select None");