Analyse an image using an external mask

Share your programming ideas for various measurement and analysis tasks here
Post Reply
user-4
Posts: 397
Joined: Thu Jan 01, 1970 1:00 am

Analyse an image using an external mask

Post by user-4 »

Code: Select all

#######################################################
## M E A S U R E M E N T   A N D   A N A L Y S I S
##
## Macro name: Analyze an image using an external mask
## Required files: 017 - FL time lapse.zvi, 017 - FL time lapse.czias
##
## LOAD IMAGE, CREATE AND SAVE IMAGE ANALYSIS SETTING,
## SEGMENT AND PROCESS NUCS, MEASURE FL INTENSITY OF ALL NUCS IN DSRed CHANNEL
## 
#######################################################
##
##
## Remove all open documents
Zen.Application.Documents.RemoveAll()
##
## Load image automatically
## Display the image
image = Zen.Application.LoadImage ('C:\\OAD\\Input\\ZVI Images\\017 - FL time lapse.zvi')
Zen.Application.Documents.Add(image)
##
## Adjust display setting automatically
d=ZenDisplaySetting()
ids = image.DisplaySetting.GetAllChannelIds()
for id in ids:
    image.DisplaySetting.SetParameter(id,'IsAutoApplyEnabled',True)
##
## Create a new measurement program for external mask
ias = ZenImageAnalysisSetting(ZenAnalysisSettingType.ExternalMask)
##
## Define a class pair
## Note! Class name must match with one mask channel name
## Note! Channel name must match with one dens channel name
ias.AddRegionClassPair("DsRed_all",1,"DsRed",2,"DsRed")
##
## Assign class colors
all = ias.GetRegionsClass("DsRed_all")
all.Color = ZenColors.Coral
single = ias.GetRegionClass("DsRed")
single.Color = ZenColors.Coral
##
## Define features (regions, region, draw)UC 38 - FL Time lapse III
all.AddFeature(ZenImageFeatures.ImageRelativeTime,True)
all.AddFeature(ZenRegionsFeaturesIntensity.RegionsIntensityMean,'DsRed')
all.AddFeature(ZenRegionsFeaturesIntensity.RegionsIntensityStd,'DsRed')
single.AddFeature(ZenRegionFeaturesGeometric.ID,True)
single.AddFeature(ZenImageFeatures.ImageIndexTime)
single.AddFeature(ZenRegionFeaturesGeometric.AreaConvex)
single.AddDrawFeature(ZenRegionFeaturesDraw.DrawBoundingRectangle)
##
## Save measurement program
ias.Save("017 - FL Time lapse")
##
## Do preprocessing and thresholding to create external mask
thres = Zen.Processing.Segmentation.ThresholdAutomatic(image,False)
#Zen.Application.Documents.Add(thres)
open = Zen.Processing.Morphology.Open(thres,1,True,ZenStructureElement.Octagon,False)
#Zen.Application.Documents.Add(open)
mask = Zen.Processing.Binary.Scrap(open,1,500,False)
Zen.Application.Documents.Add(mask)
##
## Load measurement program
ias.Load ("017 - FL Time lapse")
## Measure automatically (Run Silent)
Zen.Analyzing.Analyze(image,mask,ias)
##
## Show field table
ftable = Zen.Analyzing.CreateRegionsTable(image)
Zen.Application.Documents.Add(ftable)
##
#######################################################
user-3922
Posts: 20
Joined: Thu Jan 01, 1970 1:00 am

how to extend this example to a hierarchical class structure?

Post by user-3922 »

Thank you for the example. A good option to apply a more user-defined segmentation.

In the example it seems to be clear that the mask will be applied to the single class pair available when applying the function:

Zen.Analyzing.Analyze(image,mask,ias)

I would like to extend this idea to a more complex class structure.What do I do when i have an hierarchical class structure? How can I create different segmentation steps (masks) and relate them to the different class pairs? (I can't use the wizard for the analysis process since I need more flexibility in the segmentation process.)

An example for the class structure:

ias.AddRegionClassPair("Class_Selection", 1, "Selection", 2, "TL Brightfield")
ias.GetRegionsClass("Class_Selection").Color=ZenColor.FromRgb( 180, 0, 0 )
ias.GetRegionsClass("Class_Selection").AddFeature(ZenRegionsFeaturesGeometric.RegionsCount, True)
ias.GetRegionsClass("Class_Selection").AddFeature(ZenRegionsFeaturesGeometric.RegionsArea, True)
ias.GetRegionClass("Selection").Color=ZenColor.FromRgb( 179, 179, 179 )
ias.GetRegionClass("Selection").ImageChannelName="TL Brightfield"
ias.GetRegionClass("Selection").AddFeature(ZenRegionFeaturesGeometric.ID)
ias.GetRegionClass("Selection").AddFeature(ZenRegionFeaturesGeometric.Area)
ias.AddRegionClassPair("Selection", "Class_AOI", 3, "AOI", 4, "TL Brightfield")
ias.GetRegionsClass("Class_AOI").Color=ZenColor.FromRgb( 180, 0, 0 )
ias.GetRegionsClass("Class_AOI").AddFeature(ZenRegionsFeaturesGeometric.RegionsCount)
ias.GetRegionsClass("Class_AOI").AddFeature(ZenRegionsFeaturesGeometric.RegionsArea)
ias.GetRegionClass("AOI").Color=ZenColor.FromRgb( 255, 255, 0 )
ias.GetRegionClass("AOI").ImageChannelName="TL Brightfield"
ias.GetRegionClass("AOI").AddFeature(ZenRegionFeaturesGeometric.ID)
ias.GetRegionClass("AOI").AddFeature(ZenRegionFeaturesGeometric.Area)
ias.AddRegionClassPair("AOI", "Class_Segmentation", 5, "Segmentation", 6, "TL Brightfield")
ias.GetRegionsClass("Class_Segmentation").Color=ZenColor.FromRgb( 153, 0, 0 )
ias.GetRegionsClass("Class_Segmentation").AddFeature(ZenRegionsFeaturesGeometric.RegionsCount)
ias.GetRegionsClass("Class_Segmentation").AddFeature(ZenRegionsFeaturesGeometric.RegionsArea)
ias.GetRegionsClass("Class_Segmentation").AddFeature(ZenRegionsFeaturesIntensity.RegionsIntensitySum1, "TL Brightfield")
ias.GetRegionsClass("Class_Segmentation").AddFeature(ZenRegionsFeaturesIntensity.RegionsIntensityMean, "TL Brightfield")
ias.GetRegionClass("Segmentation").Color=ZenColor.FromRgb( 0, 0, 255 )
ias.GetRegionClass("Segmentation").ImageChannelName="TL Brightfield"
ias.GetRegionClass("Segmentation").AddFeature(ZenRegionFeaturesGeometric.ID)
ias.GetRegionClass("Segmentation").AddFeature(ZenRegionFeaturesGeometric.Area)

Does someone have an idea?

best regards,

Mark
user-4
Posts: 397
Joined: Thu Jan 01, 1970 1:00 am

Post by user-4 »

maasland wrote: I would like to extend this idea to a more complex class structure. What do I do when i have an hierarchical class structure? How can I create different segmentation steps (masks) and relate them to the different class pairs?
Replace the text in the macro

Code: Select all

Define a class pair
[B]## Note! Class name must match with one mask channel name
## Note! Channel name must match with one dens channel name[/B]
ias.AddRegionClassPair("DsRed_all",1,"DsRed",2,"DsRed")
with

Code: Select all

Define a class pair
[B]## Note! A channel name of the external mask image must match with the class name  
## Note! Channel name must match with one dens channel name[/B]
ias.AddRegionClassPair("DsRed_all",1,"DsRed",2,"DsRed")

Explanation:

The default segmenter:

For every region class
  • if segment source type is ImageChannel (default)
  • take the image, provided by the image channel name in AddRegionClassPair (last parameter)
  • segment the image with the region class specific segmenter
The external mask segmenter:

Prepare the mask image with all region class named channels

For every region class
  • take the image channel with the name of the region class from the provided mask image
  • segment the image channel binary (all pixels greater zero are true; consider minarea and fill)
A segmenter (external mask segmenter or the default segmenter) itself doesn't deal with hierarchies.


In your case:

The three herarchies have been built up via 'region class', which is correct.

The next step would be to generate the mask image with all region class named channels (via ZenImage.AddChannel) with normal IP-functions:

More precise:
For every region class
  • Segment the original input image (in most cases one of its channels) with the help of normal IP-functions to get an 2d image
  • Add the 2d image as a channel with the region class name as channel name to the mask image

I hope this helps!
user-3922
Posts: 20
Joined: Thu Jan 01, 1970 1:00 am

Post by user-3922 »

Hi!

Thank you very much for this detailed explanation. i will try to create the mask channels as suggested.

best regards,

Mark
Noah john
Posts: 1
Joined: Fri Jul 21, 2023 4:05 pm

Re: Analyse an image using an external mask

Post by Noah john »

Sure, I'd be happy to help you analyze an image using an external mask. Please provide me with the image and the mask, and I'll assist you with the analysis and I have also one other website from you can buy pregabalin 300mg online
Rose J Lever
Posts: 23
Joined: Tue Jun 20, 2023 10:20 pm

Re: Analyse an image using an external mask

Post by Rose J Lever »

To analyze an image using an external mask, overlay the mask onto the image and extract the relevant pixel data from the regions covered by the mask to perform the analysis.
If anyone want to know about Pros and Cons of Different Garage Door visit here
Post Reply