Overview

The NXT image scanner is a "stand alone" scanner that can scan and save images as a BMP-file in the NXT's flash memory. Images can be saved in either 24-bit true color, 8-bit color or gray scale. Gray scale images are scanned using the light sensor whereas color images are scanned using the HiTechnic color sensor. The scanner has a small LCD menu that let's you set the properties for the scan. Obviously the NXT image scanner is based on experience from my RCX scanner. Where the RCX scanner would take forever to scan even a small image the NXT scanner is much faster and the end result is to my own surprise improved. At the bottom of the page you will find building instructions and program for building your own image scanner.


Pictures and video

 

Frontview of the scanner
Topview of the scanner

 

The sledge uses a
worm gear for precise movement
A light sensor attached
on the sledge
View of the light sensor
The scanner in action
A worm gear is also
used to feed the paper
Three pairs of wheels
holds the paper in place
A touch sensor is used to
reset the position of
the sledge
It is easy to replace the
scanhead on the sledge
Use Bricx CC to download
the image to a PC
Completed LDraw model
Screenshot of the
set-up menu


Scanned images


Original





Normal resolution Gray Scale



Original



Normal resolution gray scale



Low resolution gray scale



Original



Low resolution gray scale



Low resolution 24-bit color


Original


Low resolution true-color


Normal resolution 8-bit color

 

How it works

Setting up a scan

There are eight options as illustrated on the figure on the right. Although most options are self explainable a few things has to be pointed out. With the "File" option it is possible to enter a name for the BMP-file. The "size" option is not changeable but will display the size of the file as well as the total available memory. When "free 3kb" is displayed it simply means that you need to free 3 kb to make the BMP-file fit in the flash memory. When the options have been accepted the arrows are used to feed the paper and adjust the scanhead. Once this is done the scanning will begin.


Scanning an image

Each line of the image is created by moving the sensor over the image at a constant speed while recording the position and corresponding sensor values with a fixed sample rate. The recorded data is then processed to make up one line of the image. The line is saved to the BMP-file and the scanner will feed the paper so the next line can be scanned. This will be repeated until the entire image has been scanned. The image processing time between each line depends on the color depth and of course the width of the image. The current status and time of the scan is printed on the screen as shown on the image - this is a screen shot from the mario scan. Once the scanning is completed the image can be downloaded to the PC using Bricx Command Center or a similar tool.

Resolution

From the set-up menu it is possible to select between three different resolutions

  • High - there will be a pixel for every 0.25 mm (100dpi)
  • Normal - there will be a pixel for every 0.50 mm (50 dpi)
  • Low - there will be a pixel every 1 mm (25 dpi)

A higher resolution will of course produce a larger file as more data is required. Since BMP images are uncompressed the high resolution can only be used to scan very small images due to limited flash memory. Saving an image in a compressed format as JPG or PNG has not been implemented (yet).

Gray scale scan

To scan an image in gray scale the standard light sensor is used in raw mode. In a gray scale color the RGB values are the same. This allows the BMP-file to be compressed to an 8-bit BMP-file where the gray color can have a value between 0 and 255. To convert the sensor readings into a value between 0 and 255 the following calculation is used:

gray scale color = 255 ·(Sensor reading - Black)
White - Black

Where Black is the sensor value that corresponds to the color black and white is the sensor value that corresponds to the color white. The light sensor is sensible to ambient - but as long as you don't flash a light near the light sensor the readings seems to be reliable. When scanning a gray scale color spectrum with different resolution the following results are achieved:


Original


Low resolution
(image has been scaled by 400%)


Normal resolution
(image has been scaled by 200%)


High resolution

Color scan

To scan an image in color the HiTecnic color sensor is used. The sensor allows you to read the raw RGB values. From the set-up menu it is possible to select between two different color depths. In the 24-bit mode the raw RGB values are stored in the BMP-file. In the 8-bit color mode the RGB values are converted using the netscape color cube. Instead of saving the raw RGB values a matching color in the color cube is found and an 8-bit reference to this color is saved in the BMP-file. This reduces the file size of the BMP-file significantly but only allows for 216 different colors. Because the color sensor is placed further from the paper than the light sensor it is more sensible to ambient light. This is also why a color scan is more blurred compared to the gray scale scan.When scanning a color spectrum with different resolution and color depths it turns out that the 8-bit color scan doesn't perform that well - this can also be seen on the scanned LEGO logo displayed above. The results from the color spectrum scan are shown below:


Original


Low resolution - true-color
(image has been scaled by 400%)


Normal resolution - true-color
(image has been scaled by 200%)


High resolution - true-color


Low resolution - 8-bit color
(image has been scaled by 400%)


Normal resolution - 8-bit color
(image has been scaled by 200%)


High resolution - 8-bit color

The images have all been altered in brightness and contrast to make them comparable with the original.

Scanner program

The program for the scanner is written in NXC and runs on the enhanced NBC/NXC firmware (version 1.06a). The source code for the scanner can be viewed by clicking on one of the four files below


You can download and use the code by clicking here. There are however a few things to note when using the scanner.

  • Delete all files before downloading the program to make room for images
  • Once the program has been loaded - use BricxCC to defrag the file system (thanks to robotmlg at the Nxtasy.org forum for pointing this out)
  • When entering a file name simply double tap "enter" to end.
  • When entering a file name the character '<' will delete a letter in the file name
  • It is not possible to see BMP-files from the NXT menu - they must be downloaded to a PC using BrixcCC or another tool
  • Not all images are suited to be scanned - chose an image without many details to get the best result - a good idea is to scan a few lines before scanning the entire image
  • If you scan a large image please be aware that it can take more than an hour to complete. So scanning an image using 6 AA batteries won't be possible.

 

Building Instructions

Below you will find building instructions for building the image scanner. Click on the image and a pop-up window with the instructions will appear. Alternatively you can download the Ldraw-files or get a a quick run through by clicking on the you tube video below. It should be noticed that the sensor cable between the NXT and the touch sensor is longer that the standard retail cable. For instructions on how to make your own cables please visit philos homepage.

Light sensor scanhead
Color sensor scanhead
Sledge
Scanner

These building instructions was made using LDraw, MLCad, LPub and POV-Ray

 

Future Improvements

All in all the results are quite good when you consider that the scanner is in fact built entirely from LEGO bricks. However there are few things that could/should be improved:

  • Add the ability to save the images in a compress image format.
  • Reduce the program size to make room for more images
  • Improve the 8-bit color scan
  • Improve the speed of the scan