Tutorials for using scikit-image, written for The Jackson Laboratory
This project is maintained by TheJacksonLaboratory
This workshop is tailored toward researchers with a working knowledge of Python. If you are a total beginner, it would be a good idea to familiarize yourself with some basic programming concepts before you begin. The Software Carpentries website might be a good place to start. You will need to be able to understand and make use of the following Python concepts:
Data can be stored in variables through assignment.
>>> a = 4
>>> b = 'test'
>>> a
4
>>> b
'test'
Variables hold data of different types (e.g., strings, integers, 64-bit floating-point numbers, etc.).
>>> type(a)
<class 'int'>
>>> type(b)
<class 'str'>
Data can be stored as lists and these can also be assigned to variables.
>>> c = [1,2,3,4]
>>> c
[1, 2, 3, 4]
>>> type(c)
<class 'list'>
Indexing can be used to select specific positions in a list.
>>> c[0]
1
>>> c[3]
4
Functions can take one or more arguments, do something with them, and return a value.
>>> def add(a, b):
... sum = a + b
... return sum
...
>>> add(1 ,3)
4
>>> add(34, 92)
126
Python’s functionality can be extended through packages and modules.
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> a = np.array([1,2,3]) #accessing the array function in the np (numpy) package to create an array object
>>> plt.hist(a)
(array([1., 0., 0., 0., 0., 1., 0., 0., 0., 1.]), array([1. , 1.2, 1.4, 1.6, 1.8, 2. , 2.2, 2.4, 2.6, 2.8, 3. ]), <a list of 10 Patch objects>)
Data can be represented as objects, which have attributes as well as associated functions called methods.
>>> a.dtype #accessing the data type of object 'a', which is a numpy array (created in #6 above)
dtype('int64')
>>> a.max() #a function that finds the maximum value of 'a'
3
Note that in Python, dot notation can be used to call an object method, e.g., a.max()
, but can also be used to call a function that is part of a package, e.g., np.array()
.
You will need to use three software tools in addition to Python for this workshop: git, conda, and jupyter.
git is only used in this workshop to copy the course notes and code to your local computer, although it is a very powerful tool for managing your projects!
conda is a tool used for two purposes: to create environments for your projects and to manage Python packages. It will be a very good idea to read up on conda before you begin this course, spefically how to use environments.
jupyter is a tool for developing your code in “notebooks” (file extension *.ipynb) in a web browser. The main utility of using notebooks for image analysis is that you can save all of your output on the same page as your code, which helps you and your collaborators to follow the steps of an analysis.
Clone the git repository to your computer.
git clone https://github.com/TheJacksonLaboratory/PythonImagingBasic.git
Windows Users: You will first need to install git. Then you can use Git Bash to use the command shown above
As an alternative to using git, you can also download the repository as a zip file from Github.
conda
Python package management systemUsing conda in a terminal window (or Anaconda prompt in Windows), create a virtual environment called ‘ImPyClass’ that uses Python3:
conda create -n ImPyClass python=3
Switch to the ImPyClass virtual environment
macOS, Linux: conda activate ImPyClass
Windows (Anaconda Prompt): activate ImPyClass
Install Scikit-Image, Numpy, Jupyter Lab, and NB_Conda:
conda install scikit-image numpy nb_conda
conda install -c conda-forge jupyterlab
jupyter lab