Snappy - GenericRegionMergingOp


I am trying to work with the segmentation operator - GenericRegionMergingOp, but it only creates an empty image.
I have used the segmentation option in SNAP and it works for my source image.
I have used other operators (like KMeansClusterAnalysis) without problems.

Any idea on what might be the problem? have you seen this working from python using the snappy api?
Any idea on how I can see on how to troubleshoot?

The source code is below.
Thank you,

source = ProductIO.readProduct(‘example.tif’)

Float = jpy.get_type(‘java.lang.Float’)
parameters = HashMap()
parameters.put(‘mergingCostCriterion’, “Spring”)
parameters.put(‘regionMergingCriterion’, “Best Fitting”)
parameters.put(‘totalIterationsForSecondSegmentation’, 50)
parameters.put(‘threshold’, Float(100.0)) #‘100.0f’
parameters.put(‘sourceBandNames’, source.getBandNames())

print (“before algorithm”)
output = GPF.createProduct(“GenericRegionMergingOp”, parameters, source)
print (“after algorithm”)

ProductIO.writeProduct(output, ‘GenericRegionMergingOp.tif’,‘GeoTIFF’)

Hi, I am creating a function to call the GenericRegionMergingOp operator.
The parameters are all set:

[totalIterationsForSecondSegmentation=50, regionMergingCriterion=Best Fitting, threshold=100.0, sourceBandNames=[Ljava.lang.String;@6e730be6, mergingCostCriterion=Spring]
(also tried with a string where the bandnames are separated by comma)

Both run (no errors) and create an empty image.
I have tried other operators (like KMeansClusterAnalysis) and they work fine.
I have tried the segmentation with my image within SNAP without problem.

Anyone has GenericRegionMergingOp working? Any clues on how I can find out what the problem is?

Thank you

I’ve merged both posts here.

You are not the first who is reporting this.

Can you try using a different output format, eg. BEAM-DIMAP or NetCDF4-CF?

@oana_hogoiu Can you have a look at this issue?

I have tried using the BEAM-DIMAP format and the result is the same: the product is created but it has only zeros.

Unfortunatelly it will not work.
There is an explanation for this:
The output product from the Write operator (within the graph) obtains a reference towards the GRM operator output band before actually running the GRM operator.
The GRM operator output band changes its source after running the algorithm, but the output product within the Write operator remains with the old reference towards the source band, created in the initialisation step.

This will be addressed in future releases.

Ok, thank you for letting me know.

Dear @oana_hogoiu,

Can you let me know if this issue is solved by the new SNAP version?

thank you

Unfortunatelly not.
I’ve created an entry for it in our issue tracker:

(you can check when it’s fixed)
Best regards,