Commit c5c28ee8 authored by aknecht2's avatar aknecht2
Browse files

Large documentation update. Added several new examples scripts. Updated...

Large documentation update.  Added several new examples scripts.  Updated image processing function documentation.
parent 71203716
......@@ -183,7 +183,7 @@ You should see your final displayed image! The :py:meth:`~ih.imgproc.Image.cont
Python Script
-------------
:download:`Download Script <../../examples/workshops/arkansas_july_2015/firstimage.py>`
:download:`Download Script <../../examples/workshops/arkansas_july_2015/firstimage.txt>`
:download:`Download Image <../images/sample/rgbsv1.png>` (same as above)
......@@ -231,7 +231,7 @@ Now that we have everything installed, we'll work through a pipeline for an imag
:download:`Team 1 Rice 0_0_2 <../../examples/workshops/arkansas_july_2015/0_0_2.png>`
:download:`The Pipeline <../../examples/workshops/arkansas_july_2015/pipeline.py>`
:download:`The Pipeline <../../examples/workshops/arkansas_july_2015/pipeline.txt>`
The pipline:
......
Camera Processing Example #1
=============================
This section will detail a shorter script that provides details on how to process
an image manually taken with a camera.
Python Script
-----------------------
:download:`Download Script <../../examples/scripts/camera1/camera1.txt>`
:download:`Download Image <../../examples/scripts/camera1/IMG_6050.JPG>`
.. code-block:: python
import ih.imgproc
plant = ih.imgproc.Image("/path/to/your/image")
plant.crop([0, "y - 210", 0, "x"])
plant.write("crop.png")
plant.colorFilter("(g > 200)")
plant.write("thresh.png")
plant.contourChop(plant.image, 300)
plant.write("chop.png")
plant.contourCut(plant.image, resize = True)
plant.write("final.png")
This script has only four processing steps but produces a very good result. Let's
look at each block
.. code-block:: python
import ih.imgproc
plant = ih.imgproc.Image("/path/to/your/image")
These two lines setup your image. The first line imports the ih image processing
module, the second loads our image. Here's what our base image looks like:
.. image:: ../../examples/scripts/camera1/IMG_6050_small.jpeg
:align: center
|
.. code-block:: python
plant.crop([0, "y - 210", 0, "x"])
plant.write("crop.png")
First, we :py:meth:`~ih.imgproc.Image.crop` the image to simply remove the pot. All ROI's are of the form
[ystart, yend, xstart, xend], so in this case we are only removing the bottom
210 pixels from the image. We then write the image:
.. image:: ../../examples/scripts/camera1/IMG_6050_crop.png
:align: center
|
.. code-block:: python
plant.colorFilter("(g > 200)")
plant.write("thresh.png")
Next, we apply a :py:meth:`~ih.imgproc.Image.colorFilter` to the image, with the
logic "g > 200". This means that we only keep pixels in the image whose green
channel is greater than 200. We then write the image:
.. image:: ../../examples/scripts/camera1/IMG_6050_thresh.png
:align: center
|
.. code-block:: python
plant.contourChop(plant.image, 300)
plant.write("chop.png")
We then use the :py:meth:`~ih.imgproc.Image.contourChop` function to remove
small contours from the image. This takes advantage of the fact that the
plant is completely connected, and the noise around it isn't. We then write
the image:
.. image:: ../../examples/scripts/camera1/IMG_6050_chop.png
:align: center
|
.. code-block:: python
plant.contourCut(plant.image, resize = True)
plant.write("final.png")
Finally, we use the :py:meth:`~ih.imgproc.Image.contourCut` function to
crop the image to just the plant, and write our final result:
.. image:: ../../examples/scripts/camera1/IMG_6050_final.png
:align: center
Command Line Script
-------------------
:download:`Download Script <../../examples/scripts/camera1/camera1.sh>`
:download:`Download Image <../../examples/scripts/camera1/IMG_6050.JPG>` (The image is identical to the one above)
.. code-block:: bash
#!/bin/bash
ih-crop --input /path/to/your/image --output crop.png --ystart 0 --yend "y - 210" --xstart 0 --xend "x"
ih-color-filter --input crop.png --output thresh.png --logic "(g > 200)"
ih-contour-chop --input thresh.png --output chop.png --binary thresh.png --basemin 300
ih-contour-cut --input chop.png --binary chop.png --output final.png --resize
This bash script performs the exact same workflow as the one above. Although not major, it is important to note the
differences between library and command line access. Command line access loads and writes an image at each step,
whereas library access loads once, and only writes when you tell it to. Additionally, script names are close to that
of the method, and all follow lower case format, with words separated by dashes, and ih pre-pendening all commands.
The most notable difference, is that a restore method is unnecessary with command-line input. We simply reuse the gray.png
file we wrote once. Additionally, there is no initial setup, you simply begin processing. The arguments passed into the
command line arguments match identically with the method arguments above.
Camera Processing Example #2
=============================
This section will detail a shorter script that provides details on how to process
an image manually taken with a camera.
Python Script
-----------------------
:download:`Download Script <../../examples/scripts/camera2/camera2.txt>`
:download:`Download Image <../../examples/scripts/camera2/IMG_0370.JPG>`
.. code-block:: python
import ih.imgproc
plant = ih.imgproc.Image("/path/to/your/image")
plant.crop([280, "y - 175", 1000, 3200])
plant.write("crop.png")
plant.colorFilter("((g - b) > 0)")
plant.write("thresh.png")
plant.contourChop(plant.image, 1000)
plant.write("chop.png")
plant.contourCut(plant.image, resize = True)
plant.write("final.png")
This script has only four processing steps but produces a very good result. Let's
look at each block
.. code-block:: python
import ih.imgproc
plant = ih.imgproc.Image("/path/to/your/image")
These two lines setup your image. The first line imports the ih image processing
module, the second loads our image. Here's what our base image looks like:
.. image:: ../../examples/scripts/camera2/IMG_0370_small.jpeg
:align: center
|
.. code-block:: python
plant.crop([280, "y - 175", 1000, 3200])
plant.write("crop.png")
First, we :py:meth:`~ih.imgproc.Image.crop` the image to remove some background
noise. All ROI's are of the form [ystart, yend, xstart, xend], so in this case
we are removing a small amount from the top and bottom of the image, and a lot
from each side. We then write the image:
.. image:: ../../examples/scripts/camera2/crop.png
:align: center
|
.. code-block:: python
plant.colorFilter("((g - b) > 0)")
plant.write("thresh.png")
Next, we apply a :py:meth:`~ih.imgproc.Image.colorFilter` to the image, with the
logic "g - b > 0". This means that we only keep pixels in the image whose green
channel is greater than the value of the blue channel. We then write the image:
.. image:: ../../examples/scripts/camera2/thresh.png
:align: center
|
.. code-block:: python
plant.contourChop(plant.image, 1000)
plant.write("chop.png")
We then use the :py:meth:`~ih.imgproc.Image.contourChop` function to remove
small contours from the image. This takes advantage of the fact that the
plant is completely connected, and the noise around it isn't. We then write
the image:
.. image:: ../../examples/scripts/camera2/chop.png
:align: center
|
.. code-block:: python
plant.contourCut(plant.image, resize = True)
plant.write("final.png")
Finally, we use the :py:meth:`~ih.imgproc.Image.contourCut` function to
crop the image to just the plant, and write our final result:
.. image:: ../../examples/scripts/camera2/final.png
:align: center
Command Line Script
-------------------
:download:`Download Script <../../examples/scripts/camera2/camera2.sh>`
:download:`Download Image <../../examples/scripts/camera2/IMG_0370.JPG>` (The image is identical to the one above)
.. code-block:: bash
#!/bin/bash
ih-crop --input /path/to/your/image --output crop.png --ystart 280 --yend "y - 175" --xstart 1000 --xend 3200
ih-color-filter --input crop.png --output thresh.png --logic "((g - b) > 0)"
ih-contour-chop --input thresh.png --output chop.png --binary thresh.png --basemin 1000
ih-contour-cut --input chop.png --binary chop.png --output final.png --resize
This bash script performs the exact same workflow as the one above. Although not major, it is important to note the
differences between library and command line access. Command line access loads and writes an image at each step,
whereas library access loads once, and only writes when you tell it to. Additionally, script names are close to that
of the method, and all follow lower case format, with words separated by dashes, and ih pre-pendening all commands.
The most notable difference, is that a restore method is unnecessary with command-line input. We simply reuse the gray.png
file we wrote once. Additionally, there is no initial setup, you simply begin processing. The arguments passed into the
command line arguments match identically with the method arguments above.
......@@ -42,7 +42,7 @@ Finally, 'and' and 'or' can be used to join together multiple pieces of logic.
Python Script
-------------
:download:`Download Script <../../examples/scripts/color1/color1.py>`
:download:`Download Script <../../examples/scripts/color1/color1.txt>`
:download:`Download Image <../images/sample/rgbtv1.png>`
......@@ -327,7 +327,3 @@ Command Line Script
This bash script performs the exact same color filtering as the above python script. Each color filter call
must be done separately. Each takes in the same input file, and writes a separate output file.
......@@ -6,7 +6,7 @@ to load, save, and show images.
Python Script
-----------------------
:download:`Download Script <../../examples/scripts/core1/core1.py>`
:download:`Download Script <../../examples/scripts/core1/core1.txt>`
:download:`Download Image <../../examples/scripts/core1/base.png>`
......@@ -189,10 +189,7 @@ Command Line Script
This bash script performs the exact same workflow as the one above. Although not major, it is important to note the
differences between library and command line access. Command line access loads and writes an image at each step,
whereas library access loads once, and only writes when you tell it to. Additionally, script names are close to that
of the method, and all follow lower case format, with words seperated by dashes, and ih prependening all commands.
of the method, and all follow lower case format, with words separated by dashes, and ih pre-pendening all commands.
The most notable difference, is that a restore method is unnecessary with command-line input. We simply reuse the gray.png
file we wrote once. Additionally, there is no initial setup, you simply begin processing. The arguments pased into the
file we wrote once. Additionally, there is no initial setup, you simply begin processing. The arguments passed into the
command line arguments match identically with the method arguments above.
......@@ -6,7 +6,7 @@ well as many core functions, such as save, restore, show, and write.
Python Script
-----------------------
:download:`Download Script <../../examples/scripts/core2/core2.py>`
:download:`Download Script <../../examples/scripts/core2/core2.txt>`
:download:`Download Image <../../examples/scripts/core2/base.png>`
......@@ -302,13 +302,10 @@ Command Line Script
This bash script should perform the exact same workflow as the one above. Although not major, it is important to note the
differences between library and command line access. Command line access loads and writes an image at each step,
whereas library access loads once, and only writes when you tell it to. Additionally, script names are close to that
of the method, and all follow lower case format, with words seperated by dashes, and ih prependening all commands.
of the method, and all follow lower case format, with words separated by dashes, and ih pre-pendening all commands.
Most arguments are the same, but because we can't specify tuples or lists from the command line, arguments like kernels and
regions of interest have to change. Individual arguments are defined, as you can see in gaussian-blur, morphology, and
color-fitler. kwidth and kheight have to specified individual, and ystart, yend, xstart, xend have to be specified individual.
-1 is assumed as the default value for roi, so any value you don't specify will be the edge for that position as specified
above. For the contour-cut 'resize' argument, you don't have to specify true, as simply adding --resize will imply
you want to resize.
you want to resize the image.
Seed Processing Example
===========================
This section details a script used for analyzing seed scans. This script, ih-seed,
comes included with the ih installation, and can be used to extract basic
metrics from a seed scan image. In this example we will process the following
image:
.. image:: ../../examples/scripts/seed/seed_small.jpeg
:align: center
From this image we will get a seed count, as well as individual length, width,
and area metrics for each seed.
:download:`Download Image <../../examples/scripts/seed/seed.jpg>`
:download:`Download Results <../../examples/scripts/seed/results.csv>`
If IH is installed you should be able to run this script simply
by typing ih-seed at the command line. You can print out all options
for the script by executing ih-seed -h. Your results should look something like this:
.. code-block:: bash
usage: ih-seed [-h] --input INPUT --output OUTPUT [--dpi DPI] [--roi ROI]
[--ystart YSTART] [--yend YEND] [--xstart XSTART] [--xend XEND]
[--writesteps]
Processes & Extracts a seed scan.
optional arguments:
-h, --help show this help message and exit
--input INPUT Path to input seed scan image.
--output OUTPUT Path to output csv file.
--dpi DPI dpi of the image.
--roi ROI roi file
--ystart YSTART Minimum Y of the roi.
--yend YEND Maximum Y of the roi.
--xstart XSTART Minimum X of the roi.
--xend XEND Maximum X of the roi.
--writesteps If specified, write processing steps.
The only arguments that really need to be talked about are the roi arguments.
You can pass in an roi as a json file with the --roi argument, or by specifying
individual bounds with the --ystart, --yend, --xstart, --xend arguments (for
more information see the ROI section on the image processing page). The passed
in roi only needs to be small enough to remove white edges around the outside
of the image, but the smaller the cropped image is the faster the processing will run.
Here's the full example arguments used to process the above image:
.. code-block:: bash
ih-seed --input seed.jpg --output results.csv --ystart 2000 --yend "y - 3000" --xstart 2000 --xend "x - 1000" --writesteps
If you haven't yet, go ahead and download the sample image (:download:`Download Image <../../examples/scripts/seed/seed.jpg>`)
and run the above command on it. Once it finishes you should end with 5 additional files.
A results.csv file containing information about each seed, and 4 image files
corresponding to the processing steps. First the image should be cropped
based on the region specified, down to just the seeds:
.. image:: ../../examples/scripts/seed/seed_crop_small.png
:align: center
Then, the seeds are thresholded using otsu's method:
.. image:: ../../examples/scripts/seed/seed_thresh_small.png
:align: center
Finally, contours in the image are removed based on their size. This lets
us keep the seeds since they are large and connected, while removing all
the background noise:
.. image:: ../../examples/scripts/seed/seed_final_small.png
:align: center
The last image generated is an image for confirming that the contours are
calculated correctly. A random color is assigned to each contour that
way it is easy to identify that seeds are being treated individually,
and are not grouped together.
.. image:: ../../examples/scripts/seed/seed_contours_small.png
:align: center
|
......@@ -8,6 +8,9 @@
ex_script_core1
ex_script_core2
ex_script_color1
ex_script_seed
ex_script_camera1
ex_script_camera2
ex_workflow_1
ex_workflow_2
arkansas_workshop_july_2015
......@@ -45,12 +48,22 @@ Color Filter
^^^^^^^^^^^^
:doc:`Color Filter #1 <ex_script_color1>`, difficulty = medium.
Seed Processing
^^^^^^^^^^^^^^^^^
:doc:`Seed Processing <ex_script_seed>`, difficulty = easy.
Processing Manual Camera Images
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
:doc:`Camera Processing #1 <ex_script_camera1>`, difficulty = easy.
:doc:`Camera Processing #2 <ex_script_camera2>`, difficulty = easy.
Workflow Examples
-----------------
:doc:`Workflow #1 <ex_workflow_1>`, difficulty = complex.
:doc:`OSG Workflows <ex_workflow_2>`
:doc:`OSG Workflows <ex_workflow_2>`, difficulty = complex.
Workshops
---------
......
import ih.imgproc
plant = ih.imgproc.Image("/path/to/your/image")
plant.crop([0, "y - 210", 0, "x"])
plant.write("crop.png")
plant.colorFilter("(g > 200)")
plant.write("thresh.png")
plant.contourChop(plant.image, 300)
plant.write("chop.png")
plant.contourCut(plant.image, resize = True)
plant.write("final.png")
#!/bin/bash
ih-crop --input /path/to/your/image --output crop.png --ystart 0 --yend "y - 210" --xstart 0 --xend "x"
ih-color-filter --input crop.png --output thresh.png --logic "(g > 200)"
ih-contour-chop --input thresh.png --output chop.png --binary thresh.png --basemin 300
ih-contour-cut --input chop.png --binary chop.png --output final.png --resize
import ih.imgproc
plant = ih.imgproc.Image("/path/to/your/image")
plant.crop([280, "y - 175", 1000, 3200])
plant.write("crop.png")
plant.colorFilter("((g - b) > 0)")
plant.write("thresh.png")
plant.contourChop(plant.image, 1000)
plant.write("chop.png")
plant.contourCut(plant.image, resize = True)
plant.write("final.png")
#!/bin/bash
ih-crop --input /path/to/your/image --output crop.png --ystart 280 --yend "y - 175" --xstart 1000 --xend 3200
ih-color-filter --input crop.png --output thresh.png --logic "((g - b) > 0)"
ih-contour-chop --input thresh.png --output chop.png --binary thresh.png --basemin 1000
ih-contour-cut --input chop.png --binary chop.png --output final.png --resize
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment