{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Thresholding"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Added new repo: imagej.public\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "",
"version_major": 2,
"version_minor": 0
},
"method": "display_data"
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "61f1f58c-8ab6-4b14-9815-cfbc4b4c8bae",
"version_major": 2,
"version_minor": 0
},
"method": "display_data"
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"net.imagej.ImageJ@2f661ef8"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"//load ImageJ\n",
"%classpath config resolver imagej.public https://maven.imagej.net/content/groups/public\n",
"%classpath add mvn net.imagej imagej 2.0.0-rc-71\n",
"\n",
"//create ImageJ object\n",
"ij = new net.imagej.ImageJ()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"There are many cases in which you might want a binary image. For example, let's say you want to binarize this image:"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
""
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"input = ij.scifio().datasetIO().open(\"http://imagej.net/images/lymp.tif\")\n",
"\n",
"ij.notebook().display(input)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Fortunately for you, ImageJ-Ops features many different algorithms that can be used to do so. Let's take a look at them!"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## [Huang Thresholding](https://imagej.net/Auto_Threshold#Huang)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
Original | Huang Thresholded |
---|
| |
"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"huang = ij.op().run(\"threshold.huang\", input)\n",
"\n",
"ij.notebook().display([[\"Original\" : input, \"Huang Thresholded\": huang]])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## IJ1 Thresholding"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"scrolled": true
},
"outputs": [
{
"data": {
"text/html": [
"Original | IJ1 Thresholded |
---|
| |
"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ij1 = ij.op().run(\"threshold.ij1\", input)\n",
"\n",
"ij.notebook().display([[\"Original\" : input, \"IJ1 Thresholded\": ij1]])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## [Intermodes Thresholding](https://imagej.net/Auto_Threshold#Intermodes)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"Original | Intermodes Thresholded |
---|
| |
"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"intermodes = ij.op().run(\"threshold.intermodes\", input)\n",
"\n",
"ij.notebook().display([[\"Original\" : input, \"Intermodes Thresholded\": intermodes]])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## [IsoData](https://imagej.net/Auto_Threshold#IsoData)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"Original | Isodata Thresholded |
---|
| |
"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"isoData = ij.op().run(\"threshold.isoData\", input)\n",
"\n",
"ij.notebook().display([[\"Original\" : input, \"Isodata Thresholded\": isoData]])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## [Li](https://imagej.net/Auto_Threshold#Li)"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"Original | Li Thresholded |
---|
| |
"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"li = ij.op().run(\"threshold.li\", input)\n",
"\n",
"ij.notebook().display([[\"Original\" : input, \"Li Thresholded\": li]])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## [MaxEntropy](https://imagej.net/Auto_Threshold#MaxEntropy)"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"Original | MaxEntropy Thresholded |
---|
| |
"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"maxEntropy = ij.op().run(\"threshold.maxEntropy\", input)\n",
"\n",
"ij.notebook().display([[\"Original\" : input, \"MaxEntropy Thresholded\": maxEntropy]])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## [Mean](https://imagej.net/Auto_Threshold#Mean)"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"Original | Mean Thresholded |
---|
| |
"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"mean = ij.op().run(\"threshold.mean\", input)\n",
"\n",
"ij.notebook().display([[\"Original\" : input, \"Mean Thresholded\": mean]])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## [MinError](https://imagej.net/Auto_Threshold#MinError.28I.29)"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"Original | MinError Thresholded |
---|
| |
"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"minError = ij.op().run(\"threshold.minError\", input)\n",
"\n",
"ij.notebook().display([[\"Original\" : input, \"MinError Thresholded\": minError]])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## [Minimum](https://imagej.net/Auto_Threshold#Minimum)"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"Original | Minimum Thresholded |
---|
| |
"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"minimum = ij.op().run(\"threshold.minimum\", input)\n",
"\n",
"ij.notebook().display([[\"Original\" : input, \"Minimum Thresholded\": minimum]])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## [Moments](https://imagej.net/Auto_Threshold#Moments)"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"Original | Moments Thresholded |
---|
| |
"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"moments = ij.op().run(\"threshold.moments\", input)\n",
"\n",
"ij.notebook().display([[\"Original\" : input, \"Moments Thresholded\": moments]])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## [Otsu](https://imagej.net/Auto_Threshold#Otsu)"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"Original | Otsu Thresholded |
---|
| |
"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"otsu = ij.op().run(\"threshold.otsu\", input)\n",
"\n",
"ij.notebook().display([[\"Original\" : input, \"Otsu Thresholded\": otsu]])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## [Percentile](https://imagej.net/Auto_Threshold#Percentile)"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"Original | Percentile Thresholded |
---|
| |
"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"percentile = ij.op().run(\"threshold.percentile\", input)\n",
"\n",
"ij.notebook().display([[\"Original\" : input, \"Percentile Thresholded\": percentile]])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## [RenyiEntropy](https://imagej.net/Auto_Threshold#RenyiEntropy)"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"Original | RenyiEntropy Thresholded |
---|
| |
"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"renyiEntropy = ij.op().run(\"threshold.renyiEntropy\", input)\n",
"\n",
"ij.notebook().display([[\"Original\" : input, \"RenyiEntropy Thresholded\": renyiEntropy]])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## [Shanbhag](https://imagej.net/Auto_Threshold#Shanbhag)"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"Original | Shanbhag Thresholded |
---|
| |
"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"shanbhag = ij.op().run(\"threshold.shanbhag\", input)\n",
"\n",
"ij.notebook().display([[\"Original\" : input, \"Shanbhag Thresholded\": shanbhag]])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## [Triangle](https://imagej.net/Auto_Threshold#Triangle)"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"Original | Triangle Thresholded |
---|
| |
"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"triangle = ij.op().run(\"threshold.triangle\", input)\n",
"\n",
"ij.notebook().display([[\"Original\" : input, \"Triangle Thresholded\": triangle]])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## [Yen](https://imagej.net/Auto_Threshold#Yen)"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"Original | Yen Thresholded |
---|
| |
"
]
},
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"yen = ij.op().run(\"threshold.yen\", input)\n",
"\n",
"ij.notebook().display([[\"Original\" : input, \"Yen Thresholded\": yen]])"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Groovy",
"language": "groovy",
"name": "groovy"
},
"language_info": {
"codemirror_mode": "groovy",
"file_extension": ".groovy",
"mimetype": "",
"name": "Groovy",
"nbconverter_exporter": "",
"version": "2.4.3"
},
"toc": {
"base_numbering": 1,
"nav_menu": {},
"number_sections": true,
"sideBar": true,
"skip_h1_title": true,
"title_cell": "Table of Contents",
"title_sidebar": "Contents",
"toc_cell": false,
"toc_position": {
"height": "calc(100% - 180px)",
"left": "10px",
"top": "150px",
"width": "307px"
},
"toc_section_display": true,
"toc_window_display": true
}
},
"nbformat": 4,
"nbformat_minor": 2
}