回答
不幸的是,這個任務並不像人們希望的那樣簡單直接。
雖然腳本支持將圖像操作限制爲矩形ROI(使用img[]
表示法)的方便快捷方式,但對於不規則的ROI,沒有這種功能。
在這種情況下,必須手動創建ROI的二進制掩碼並手動執行想要的操作。本文後面的示例腳本顯示瞭如何計算不規則ROI的平均值。
CreateImageWithROI()
創建一個測試圖像與在其上兩個ROIGetFirstIrregularROIOfImage()
只是返回一個圖像的第一發現,不規則ROIGetROIMean()
是實際的示例
命令ROIAddToMask()
用於創建面具。注意,也有一個類似的命令,會立即與圖像顯示的所有的ROI執行的操作:ImageDisplayAccumulateROIsToMask()
到目前爲止,一切都很好。
然而,事實證明,新引進的圓形的ROI還不支持面具創造命令正確(測試與GMS 3.1)。
相反,他們總是用ROI的邊框:
因此,有必要去,即使退一萬步,並宣讀了ROI的座標手動從它創建一個面具。獲取ROI的邊界框並使用橢圓的icol
和irow
表達式創建一個遮罩。在下面的例子:
GetFirstOvalROIOfImage()
只是返回一個圖像MyAddOvalROIToMask()
的第一發現,橢圓形ROI是手動掩模製作爲橢圓形的ROI
實施例代碼:
image CreateImageWithROI()
{
// Create and show image
number sx = 256, sy = 256
image img := RealImage("Image", 4, sx, sy)
img = sin(0.1 * iradius) * cos(7 * itheta)
img.ShowImage()
// Create an irregular, closed ROI
ROI myIrRoi = NewROI()
myIrRoi.ROIAddVertex(0.3 * sx, 0.1 * sy)
myIrRoi.ROIAddVertex(0.7 * sx, 0.2 * sy)
myIrRoi.ROIAddVertex(0.5 * sx, 0.6 * sy)
myIrRoi.ROIAddVertex(0.1 * sx, 0.8 * sy)
myIrRoi.ROISetIsClosed(1)
myIRRoi.ROISetVolatile(0)
// Create an oval ROI
ROI myOvalROI = NewROI()
myOvalROI.ROISetOval(0.7 * sy, 0.7 * sx, 0.9 * sy, 0.8 * sx)
myOvalROI.ROISetVolatile(0)
// AddROIs
imageDisplay disp = img.ImageGetImageDisplay(0)
disp.ImageDisplayAddROI(myIRRoi)
disp.ImageDisplayAddROI(myOvalROI)
return img
}
ROI GetFirstIrregularROIOfImage(image img)
{
if (img.ImageIsValid())
{
if (0 != img.ImageCountImageDisplays())
{
imageDisplay disp = img.ImageGetImageDisplay(0)
number nRois = disp.ImageDisplayCountROIs()
for (number i = 0; i < nRois; i++)
{
ROI testROI = disp.ImageDisplayGetRoi(i)
number isIrregularClosed = 1
isIrregularClosed *= testROI.ROIIsClosed();
isIrregularClosed *= !testROI.ROIIsOval();
isIrregularClosed *= !testROI.ROIIsRectangle();
isIrregularClosed *= (2 < testROI.ROICountVertices());
if (isIrregularClosed)
return testROI
}
}
}
Throw("No irregular ROI found")
}
ROI GetFirstOvalROIOfImage(image img)
{
if (img.ImageIsValid())
{
if (0 != img.ImageCountImageDisplays())
{
imageDisplay disp = img.ImageGetImageDisplay(0)
number nRois = disp.ImageDisplayCountROIs()
for (number i = 0; i < nRois; i++)
{
ROI testROI = disp.ImageDisplayGetRoi(i)
if (testROI.ROIIsOval())
return testROI
}
}
}
Throw("No oval ROI found")
}
void MyAddOvalROIToMask(image img, ROI ovalROI)
{
number top, left, bottom, right
ovalROI.ROIGetOval(top, left, bottom, right)
number sx = (right - left)
number sy = (bottom - top)
number cx = sx/2 // Used as both center x coordiante and x radius!
number cy = sy/2 // Used as both center y coordiante and y radius!
// Create mask of just the rect area
image maskCut := RealImage("", 4, sx, sy)
maskCut = (((cx-icol)/cx)**2 + ((cy-irow)/cy)**2 <= 1) ? 1 : 0
// Apply mask to image
img[top, left, bottom, right] = maskCut
}
number GetROIMean(image img, ROI theRoi)
{
if (!img.ImageIsValid()) Throw("Invalid image in GetROIMean()")
if (!theRoi.ROIIsValid()) Throw("Invalid roi in GetROIMean()")
// Create a binary mask of "img" size using the ROI's coordinates
image mask = img * 0; // image of same size as "img" with 0 values
number sx, sy
img.GetSize(sx, sy)
// Oval ROIs are not supported by the command correctly
// Hence check and compute mask manually..
if (theROI.ROIIsOval())
MyAddOvalROIToMask(mask, theROI)
else
theROI.ROIAddToMask(mask, 0, 0, sx, sy)
if (TwoButtonDialog("Show mask?", "Yes", "No"))
mask.ShowImage()
// Do meanValue as sums of masked points
number maskedPoints = sum(mask)
number maskedSum
if (0 < maskedPoints)
maskedSum = sum(mask * img)/maskedPoints
else
maskedSum = sum(img)
return maskedSum
}
Result("\n Testing irregular and oval ROIs on image.\n")
image testImg := CreateImageWithROI()
ROI testROIir = GetFirstIrregularROIOfImage(testImg)
number ROIirMean = GetROIMean(testImg, testROIir)
Result("\n Mean value (irregular ROI): "+ ROIirMean)
ROI testROIoval = GetFirstOvalROIOfImage(testImg)
number ROIovalMean = GetROIMean(testImg, testROIoval)
Result("\n Mean value (oval ROI) : "+ ROIovalMean)
非常感謝您的幫助。我可以在我的數據處理中使用這些提示。 –
順便說一句,同樣的方法也適用於圓形註釋(在GMS 2和更早的版本中),這樣也可以在這種情況下獲得「循環ROI」。 – BmyGuest
- 1. 使用ADSI腳本獲取Netlogon信息
- 2. 不使用While循環從數據庫獲取單元信息
- 3. 如何使用腳本瀏覽網站以獲取信息
- 4. 如何使用Lotus腳本獲取系統/磁盤信息?
- 5. 如何從使用javascript的循環中的字段獲取信息
- 6. 獲取信息後外WordPress的循環
- 7. 獲取循環外的信息
- 8. 使用python腳本從網絡投影儀獲取信息
- 9. 使用RefManageR獲取來自PMID的PubMed信息 - 在循環中
- 10. 使用while循環獲取Swift郵件中的詳細信息
- 11. 我如何循環使用Groovy腳本
- 12. udev/Bash腳本來獲取USB信息
- 13. 獲取內存信息的腳本
- 14. 如何從WebContext獲取用戶信息?
- 15. 如何從Facebook獲取用戶信息?
- 16. 從沒有循環的數組中獲取信息
- 17. 使用Scrapy從使用java腳本生成數據的網站獲取信息
- 18. 如何使用Google應用腳本獲取用戶創建的組信息
- 19. 如何在此腳本的for循環中使用for循環?
- 20. 如何使用PHP獲取信息?
- 21. 如何使用java獲取BIOS信息?
- 22. 如何使用LINQ獲取此信息
- 23. 如何在循環has_many時從連接表中獲取信息:通過
- 24. 如何製作一個能夠從txt文件獲取信息的循環?
- 25. 如何從調用應用程序獲取版本信息
- 26. 無法使用shell腳本獲取進程信息
- 27. 使用rapidminer來獲取文本信息
- 28. 循環用戶信息
- 29. 如何循環PHP腳本
- 30. 如何循環腳本
您是指GMS 3功能「橢圓ROI」還是橢圓註釋(也來自以前的GMS版本)? – BmyGuest
你的第二個問題還不清楚。 「鏈接職位」是什麼意思? ROI只是座標的集合。您可以閱讀ROI(即找到中心)並將ROI設置爲某些(即將ROI轉移到某個位置),如果是,請提問。 – BmyGuest