(last update: Mon Aug 15 07:05:15 CEST 2016)

The Remote Image Processing system (RIPS)

During this course we will develop a client/server system for multithreaded image processing. The system will implement various algorithms, including:

You are provided with a skeleton of the code for the client and server applications (you will need to add the assembly System.Drawing.dll to your project):

You are also provided with some example images in BMP format.

Overview

All image processing is performed on the server. The client only loads from a file the images to process, connects to the server, and writes to disk the output image after the server sends them back to the client.

Client and server use the BitTorrent Bencode format to communicate.

The client locates the server using an online database of servers, where previously the server has registered the IP and port on which it receives requests. The server updates this online database using an HTTP request every time it starts. The server uses the Windows Registry to store some configuration.

Detailed behavior

Client (see the Client.Run method, already given to you):

  1. Parses commandline arguments (class ClientOptions, code provided)
  2. Finds out the IP and port of the server to connect (Client.LocateServer)
  3. Connects to the server (Client.Connect)
  4. Sends the images and parameters of the algorithm to the server (Client.Histogram, etc), and receives the results.
  5. Stores the output image in a file
  6. Closes the connection and exits (Client.Disconnect)

Server (see the Server.Run method, already given to you):

  1. Initializes the Windows Registry with default configuration parameters if it detects that no configuration is present (Server.InitRegistry)
  2. Loads from the Windows Registry the IP and port where the server will listen, and binds a TCP socket to that service point (Server.Listen)
  3. Registers in the online database its listening IP and port, so that clients can find the server (Server.Register)
  4. Accepts new clients in the Server.Work method, creating a new thread for each one of them (class ServerConnection). That thread executes the method ServerConnection.ConnectionThread.
  5. The connection thread parses the client's request, including the image processing algorithm to be applied and the number of worker threads.
  6. It then partitions the image and creates multiple threads to perform the task. The threads execute the method WorkerParams.WorkerThread.
  7. When all worker threads finish, they notify this to the connection thread, who sends back the output image to the client, and closes the connection.

Commandline Syntax for the Client

The RIPS client will be a commandline application with the following syntax:

Usage: Client REQUEST IMAGE1 [IMAGE2] [OPTIONS]

Where REQUEST can be one of the following

 histogram     - Outputs the histogram of IMAGE, by default to 'out.txt'
 bw            - Transforms IMAGE1 into grayscales
 blur          - Blurs the image and stores the result, by default, to 'out.bmp'
 merge         - Fuses IMAGE1 (foreground) and IMAGE2 (background) into one
                 single image, output to 'out.bmp'

and where [OPTIONS] are zero or more options from the following list:

 /out:FILE     - Saves the result image or histogram in FILE instead of the
                 default file indicated above

 /nthreads:N   - The server will use 2^N threads (default 2, ie, 4 threads used)

 /contour:N    - (only for 'blur') Compute pixel averages using the N surrounding
                 'rings' (default 3)

 /alpha:N      - (only for 'merge') Set the transparency of IMAGE1 to N percent,
                 where 0% means IMAGE1 is completely opaque and 100% means it is
                 completely transparent (default 50)

Here are some examples of invocation:

  • Compute the histogram of the file lena.bmp and store it in hist.txt. By default 4 threads are used to perform the computation:

    Client.exe histogram lena.bmp /out:hist.txt
    
  • Blur the image lena.bmp using 32 threads and mixing the 2 rings of pixels that surround every pixel:

    Client.exe blur lena.bmp /nthreads:5 /contour:2
    
  • Mix the images lena.bmp and background.bmp into one single image whose pixels are defined as 15% of lena.bmp and 85% of background.bmp. Uses 16 threads:

    Client.exe merge lena.bmp background.bmp /nthreads:4 /alpha:15