Get total surface of pixels over threshold without counting objects
Hi,
Is there a way to just get the total amount of pixels thresholded in an image without having to create and count all the objects.
Thank you
Is there a way to just get the total amount of pixels thresholded in an image without having to create and count all the objects.
Thank you
0
Answers
-
You can use Histogram to calculate total object area and percentage area.
The macro below assumes that the background intensity is 0 and objects have intensities above 0 (as on thresholded image).' 'Calculates object area on image using histogram 'objects are any pixels with values above 0 ' Public Sub GetObjectAreaUsingHist Dim im As McImage=ThisApplication.ActiveImage If im Is Nothing Then Exit Sub Dim pixSize As Double = 1 If im.SpatialCalibration IsNot Nothing Then 'calibrated pixel size pixSize = im.SpatialCalibration.PixelSizeX * im.SpatialCalibration.PixelSizeY End If Dim hist As MediaCy.IQL.Operations.McHistogram=im.Histogram 'calculate areas using histogram 'get all bin values Dim allVals As Double() = hist.Values(-1, 0)'use mono image or channel 1 Dim areaPix As Double = 0 For bin As Integer = allVals.GetLowerBound(0) To allVals.GetUpperBound(0) areaPix = areaPix + allVals(bin) Next Dim zeroArea As Double = allVals(allVals.GetLowerBound(0)) 'number of pixels in 0 bin 'Area in calibrated units Debug.Print "Total Object Area = " & (areaPix - zeroArea) * pixSize 'AreaPercent If areaPix > 0 Then Debug.Print "Area Percentage = " & ( 100.0 * (areaPix - zeroArea) / areaPix) End If End Sub
Yuri0
Categories
- All Categories
- 961 Image-Pro v9 and higher
- 9 Image-Pro FAQs
- 18 Image-Pro Download & Install
- 448 Image-Pro General Discussions
- 486 Image-Pro Automation (Macros, Apps, Reports)
- 20 AutoQuant Deconvolution
- 2 AutoQuant Download & Install
- 18 AutoQuant General Discussions
- 195 Image-Pro Plus v7 and lower
- 3 Image-Pro Plus Download & Install
- 106 Image-Pro Plus General Discussions
- 86 Image-Pro Plus Automation with Macros
- 19 Legacy Products
- 16 Image-Pro Premier 3D General Discussions
- 26 Image-Pro Insight General Discussions