Computer vision lab: pixels, thresholds and counting objects in JupyterLab
This lab gives each student a JupyterLab of their own, with the Python image libraries already in it: Pillow to open and change pictures, NumPy for the numbers and scikit-image for edges, labelling and matching. The work folder holds five pictures the lab draws itself, coins, shapes, a road, a page scan and a grey ramp, a starter notebook and short scripts, one idea each.
It is not an attack lab. Every copy has no route to the internet and none to any other student, so nothing can be downloaded into it and nothing in it can reach anybody else. It teaches the ideas under computer vision with plain pixels, not neural networks, and it has no OpenCV.
What students learn
That a picture is a grid of numbers: its size, its mode and the values of single pixels. Then turning colour to grey and counting how many pixels fall in each band, choosing a threshold to split dark from bright and seeing that one level separates nine coins from a noisy background while another does not, blurring a page scan to calm its speckle, finding edges, counting objects by labelling, resizing and cropping with the file size they cost, and finding a piece of a picture inside it by template matching. It suits introductions to computer vision, image processing and applied maths; check your own awarding body’s unit for the exact wording, none is quoted here.
Run it in your browser
The lab starts one service, jupyter, which draws the pictures, writes the notebook and the short scripts into its work folder and is ready in a few seconds, inside the 512 MB a service may have. JupyterLab asks for no token, because the platform’s own door already knows who is opening it. The terminal beside the lab has no Python of its own, so it reaches the lab’s with docker exec jupyter, followed by the command to run inside. Every script prints the same each time, and saves a picture where that helps, which a student opens in JupyterLab.
- Open the Container page. Open Build on the bar and choose Run a container. Anybody may open it, and the Git lab and the SQL lab start with no account. Every other lab needs a free account: create one, sign in, then press Start.
- Find the lab. The Sample labs card lists every sample. Find JupyterLab: computer vision with Pillow and scikit-image.
- Press Start. Start runs it as it is, in one press. Edit the file first opens the compose file so you can change it before you start.
- Open it. On the lab’s page, the lab bar has a link called JupyterLab: press it to open JupyterLab in your browser, open the images folder and double-click start.ipynb. Then press Open terminal and type docker exec jupyter python3 steps/count.py to count the coins: it answers 9 objects, the nine coins the lab drew, in three sizes.
What to ask students to hand in
A notebook of their own over one of the pictures that answers one question they chose, such as how many pixels pass a threshold and why they chose that level, how much a blur lowers the speckle on the page scan, or whether one threshold works across the whole of the uneven page scan, downloaded from JupyterLab with File, Download. Then a sentence or two in their own words on what they found and what they checked by eye. Nothing is marked automatically: the sentence shows whether it was understood. For stronger work ask for the mask drawn beside the picture and a count compared with the number they can see.
A basic lesson on this lab
Computer Vision Basics is a small lesson worked in this lab. In it a student lists the pictures, reads a pixel, turns a picture to grey, tries three thresholds, blurs a noisy scan, counts the coins by labelling, and then opens the same work in the starter notebook.
It is deliberately small: it shows a teacher what a lesson worked in a lab is, and the lab does the rest. Copy it into a module of your own to change it.
The code on GitHub
The compose file has no Dockerfile: it runs one stock public image, the Jupyter Docker Stacks’ own scipy-notebook, pinned to a dated tag, as its own unprivileged account with 512 MB of memory. The image is licensed BSD-3-Clause and is not distributed by us. The file draws every picture from a fixed seed when it starts, so every copy has the same numbers and nothing is downloaded. The limits are honest ones: the pictures are small and made up, there is no camera and no photograph, there is no GPU, nothing can be installed from the internet, and the methods are the classic ones, not a neural network. Nothing is kept when the lab stops, so a student downloads their notebook first.
Set it as work
Say in the task what to hand in.
- Make the lab. In your module add a task and choose the Container lab card, then In a GitHub repository. Give https://github.com/mitsurutech/lab-computer-vision with the branch main. The compose file is the default, compose.yaml. Fork the repository first if you want to change it, for example to draw different pictures.
- Publish and try it. Publish pins the commit you were shown, so a later change in the repository does not alter a lab you have already set. Start your own copy first.
- Hand it out. Assign it like any task, with a due date if you want one, and say in the task what to do and what to hand in.
- Mark what is handed in. Open a student’s copy and the work they handed in, mark it, and send it back with a reason if it needs more.
Try this lab, and what it costs
A free personal account can work through the basic lessons in this lab, with enough free credit each month to follow most lessons and no card. For a class, a school or college has its first 365 days free for up to 50 students, then pays per student a year, with every lab included and staff free.
Questions people ask
- Why is there no token or password to type?
- A lab’s web page is reached only through the platform’s own door, which already knows who you are and lets in only you and the staff who teach your module. So JupyterLab is started with no token. Do not run it like that on a machine anybody else can reach.
- Why does the terminal use docker exec jupyter?
- The lab’s terminal carries curl, psql and a few other clients, and no Python. docker exec jupyter runs a command inside the lab’s own container, which has Python and every library. JupyterLab also has a terminal of its own, under File, New, Terminal.
- Can students use their own photographs?
- A student can upload a picture into JupyterLab from their own computer and the same scripts open it, but nothing is downloaded by the lab and the copy cannot reach the internet. The numbers on this page are for the pictures the lab draws. To change those, fork the repository, change how the compose file draws them, and set the fork as the lab.