Post

2 followers Follow
0
Avatar

Access Image Statistics in Python

Is there a way to get image statistics for different channels in Geomatica through Python (i.e. mean, median, mode, standard deviation, etc)? Sorry if this is a newb question, Im still new to Geomatica.

Christiaan Lott Answered

Please sign in to leave a comment.

2 comments

1
Avatar

Hi Christiaan,

You can use the HIS algorithm to get the channel statistics. The example below shows how to run HIS on one image channel. If you wish to output the results to a report file you can implement the Report class. The answer to a previous question outlines how to create a report: http://support.pcigeomatics.com/hc/communities/public/questions/203566673-Write-report-to-file-in-python

from pci.his import his

image = r"C:\PCI Geomatics\Geomatica 2015\demo\irvine.pix"

imstat = []
his(file=image,
      dbic=[1],
      imstat=imstat)

You will notice above that an empty list "imstat" is created before HIS is run. This empty list will be populated with the channel statistics from the "imstat" output parameter. If multiple channels are listed, the channel information from the last channel will be written out to the imstat parameter. In the example above the statistics from channel 1 will be written to the stats variable There are 13 values added to this list after HIS is run. A list of the 13 values is available from the Geomatica help: http://www.pcigeomatics.com/geomatica-help/index.html?page=references%2Fpcifunction_r%2Fpython%2Fp_his.html

You can create other variables for each statistic from imstat. Keep in mind that the first imstat value (channel number) would be imstat[0] as per python’s numbering scheme.

channel = imstat[0]
mean = imstat[1]
median = imstat[2]

print channel, mean, median

Hope this helps,
Sarah

PCI Geomatics 1 vote