Skip to content

Instantly share code, notes, and snippets.

@larrybradley
Last active August 29, 2015 14:16
Show Gist options
  • Save larrybradley/d06a3af40207ed4cd821 to your computer and use it in GitHub Desktop.
Save larrybradley/d06a3af40207ed4cd821 to your computer and use it in GitHub Desktop.
imstats
Display the source blob
Display the rendered blob
Raw
{
"metadata": {
"name": "",
"signature": "sha256:c26e51ab7135292c1024070f5033a3c60ca66da5c2523516d0ec411907747f4c"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "code",
"collapsed": false,
"input": [
"# create dummy images (random Gaussian noise)\n",
"import numpy as np\n",
"size = (1000, 1000)\n",
"img1 = np.random.normal(loc=0., scale=5., size=size)\n",
"img2 = np.random.normal(loc=10., scale=25., size=size)"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 1
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"import imutils\n",
"imutils.imstats(img1)"
],
"language": "python",
"metadata": {},
"outputs": [
{
"html": [
"<Table masked=False length=1>\n",
"<table id=\"table4476527952\">\n",
"<thead><tr><th>name</th><th>npix</th><th>mean</th><th>std</th><th>min</th><th>max</th></tr></thead>\n",
"<thead><tr><th>object</th><th>int64</th><th>float64</th><th>float64</th><th>float64</th><th>float64</th></tr></thead>\n",
"<tr><td>None</td><td>997334</td><td>-0.00076865386916</td><td>4.93314138755</td><td>-14.9988137598</td><td>14.9956656932</td></tr>\n",
"</table>"
],
"metadata": {},
"output_type": "pyout",
"prompt_number": 2,
"text": [
"<Table masked=False length=1>\n",
" name npix mean std min max \n",
"object int64 float64 float64 float64 float64 \n",
"------ ------ ----------------- ------------- -------------- -------------\n",
" None 997334 -0.00076865386916 4.93314138755 -14.9988137598 14.9956656932"
]
}
],
"prompt_number": 2
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"imutils.imstats(img1, sigma=4.5, iters=5)"
],
"language": "python",
"metadata": {},
"outputs": [
{
"html": [
"&lt;Table masked=False length=1&gt;\n",
"<table id=\"table4443609104\">\n",
"<thead><tr><th>name</th><th>npix</th><th>mean</th><th>std</th><th>min</th><th>max</th></tr></thead>\n",
"<thead><tr><th>object</th><th>int64</th><th>float64</th><th>float64</th><th>float64</th><th>float64</th></tr></thead>\n",
"<tr><td>None</td><td>997334</td><td>-0.00076865386916</td><td>4.93314138755</td><td>-14.9988137598</td><td>14.9956656932</td></tr>\n",
"</table>"
],
"metadata": {},
"output_type": "pyout",
"prompt_number": 3,
"text": [
"<Table masked=False length=1>\n",
" name npix mean std min max \n",
"object int64 float64 float64 float64 float64 \n",
"------ ------ ----------------- ------------- -------------- -------------\n",
" None 997334 -0.00076865386916 4.93314138755 -14.9988137598 14.9956656932"
]
}
],
"prompt_number": 3
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"imutils.imstats(img1, name='macs0467')"
],
"language": "python",
"metadata": {},
"outputs": [
{
"html": [
"&lt;Table masked=False length=1&gt;\n",
"<table id=\"table4443609296\">\n",
"<thead><tr><th>name</th><th>npix</th><th>mean</th><th>std</th><th>min</th><th>max</th></tr></thead>\n",
"<thead><tr><th>string64</th><th>int64</th><th>float64</th><th>float64</th><th>float64</th><th>float64</th></tr></thead>\n",
"<tr><td>macs0467</td><td>997334</td><td>-0.00076865386916</td><td>4.93314138755</td><td>-14.9988137598</td><td>14.9956656932</td></tr>\n",
"</table>"
],
"metadata": {},
"output_type": "pyout",
"prompt_number": 4,
"text": [
"<Table masked=False length=1>\n",
" name npix mean std min max \n",
"string64 int64 float64 float64 float64 float64 \n",
"-------- ------ ----------------- ------------- -------------- -------------\n",
"macs0467 997334 -0.00076865386916 4.93314138755 -14.9988137598 14.9956656932"
]
}
],
"prompt_number": 4
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"mask1 = img1 > 0.\n",
"imutils.imstats(img1, name='macs0467', mask=mask1)"
],
"language": "python",
"metadata": {},
"outputs": [
{
"html": [
"&lt;Table masked=False length=1&gt;\n",
"<table id=\"table4443608336\">\n",
"<thead><tr><th>name</th><th>npix</th><th>mean</th><th>std</th><th>min</th><th>max</th></tr></thead>\n",
"<thead><tr><th>string64</th><th>int64</th><th>float64</th><th>float64</th><th>float64</th><th>float64</th></tr></thead>\n",
"<tr><td>macs0467</td><td>493539</td><td>-3.85881547933</td><td>2.79194407448</td><td>-12.403409532</td><td>-1.64664762426e-05</td></tr>\n",
"</table>"
],
"metadata": {},
"output_type": "pyout",
"prompt_number": 5,
"text": [
"<Table masked=False length=1>\n",
" name npix mean std min max \n",
"string64 int64 float64 float64 float64 float64 \n",
"-------- ------ -------------- ------------- ------------- ------------------\n",
"macs0467 493539 -3.85881547933 2.79194407448 -12.403409532 -1.64664762426e-05"
]
}
],
"prompt_number": 5
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"# all of the currently available stats\n",
"columns = ['name', 'npix', 'mean', 'median', 'mode', 'std',\n",
" 'mad_std', 'biweight_location', 'biweight_midvariance',\n",
" 'min', 'max', 'skew', 'kurtosis']\n",
"imutils.imstats(img1, name='macs0467', columns=columns)"
],
"language": "python",
"metadata": {},
"outputs": [
{
"html": [
"&lt;Table masked=False length=1&gt;\n",
"<table id=\"table4443609424\">\n",
"<thead><tr><th>name</th><th>npix</th><th>mean</th><th>median</th><th>mode</th><th>std</th><th>mad_std</th><th>biweight_location</th><th>biweight_midvariance</th><th>min</th><th>max</th><th>skew</th><th>kurtosis</th></tr></thead>\n",
"<thead><tr><th>string64</th><th>int64</th><th>float64</th><th>float64</th><th>float64</th><th>float64</th><th>float64</th><th>float64</th><th>float64</th><th>float64</th><th>float64</th><th>float64</th><th>float64</th></tr></thead>\n",
"<tr><td>macs0467</td><td>997334</td><td>-0.00076865386916</td><td>-0.00103923743353</td><td>-0.00158040456228</td><td>4.93314138755</td><td>4.98970211972</td><td>-0.00142144480231</td><td>5.01113709939</td><td>-14.9988137598</td><td>14.9956656932</td><td>0.00119574877216</td><td>-0.175119601644</td></tr>\n",
"</table>"
],
"metadata": {},
"output_type": "pyout",
"prompt_number": 6,
"text": [
"<Table masked=False length=1>\n",
" name npix mean ... skew kurtosis \n",
"string64 int64 float64 ... float64 float64 \n",
"-------- ------ ----------------- ... ---------------- ---------------\n",
"macs0467 997334 -0.00076865386916 ... 0.00119574877216 -0.175119601644"
]
}
],
"prompt_number": 6
},
{
"cell_type": "heading",
"level": 1,
"metadata": {},
"source": [
"Multiple Images"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"data = [img1, img2]\n",
"names = ['macs0467', 'm51']\n",
"mask1 = img1 > 0\n",
"mask2 = img2 > 10\n",
"masks = [mask1, mask2]\n",
"columns = ['name', 'npix', 'mean', 'median', 'mode', 'std', 'min', 'max']\n",
"imutils.imstats(data, name=names, mask=masks, columns=columns)"
],
"language": "python",
"metadata": {},
"outputs": [
{
"html": [
"&lt;Table masked=False length=2&gt;\n",
"<table id=\"table4572361104\">\n",
"<thead><tr><th>name</th><th>npix</th><th>mean</th><th>median</th><th>mode</th><th>std</th><th>min</th><th>max</th></tr></thead>\n",
"<thead><tr><th>string64</th><th>int64</th><th>float64</th><th>float64</th><th>float64</th><th>float64</th><th>float64</th><th>float64</th></tr></thead>\n",
"<tr><td>macs0467</td><td>493539</td><td>-3.85881547933</td><td>-3.32448065528</td><td>-2.25581100718</td><td>2.79194407448</td><td>-12.403409532</td><td>-1.64664762426e-05</td></tr>\n",
"<tr><td>m51</td><td>492503</td><td>-9.27975588479</td><td>-6.61309044021</td><td>-1.27975955106</td><td>13.964694994</td><td>-51.9768084734</td><td>9.99996698143</td></tr>\n",
"</table>"
],
"metadata": {},
"output_type": "pyout",
"prompt_number": 8,
"text": [
"<Table masked=False length=2>\n",
" name npix mean ... min max \n",
"string64 int64 float64 ... float64 float64 \n",
"-------- ------ -------------- ... -------------- ------------------\n",
"macs0467 493539 -3.85881547933 ... -12.403409532 -1.64664762426e-05\n",
" m51 492503 -9.27975588479 ... -51.9768084734 9.99996698143"
]
}
],
"prompt_number": 8
},
{
"cell_type": "code",
"collapsed": false,
"input": [],
"language": "python",
"metadata": {},
"outputs": []
}
],
"metadata": {}
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment