A grayscale digital image is a two-dimensional raster image in which the picture elements, or pixels, store a single value representing a shade of gray that varies from black to white. In a discrete grayscale image, the shades of gray are represented by integer values in the range [0 to 255], where 0 is black and 255 is white. We can define the Grayscale Image ADT for storing and manipulating discrete grayscale digital images.
Given the description of the operations, provide a complete implementation of the ADT using a 2-D array.

  1. GrayscaleImage( nrows, ncols ): Creates a new instance that consists of nrows and ncols of pixels each set to an initial value of 0.
  2. width (): Returns the width of the image.
  3. height (): Returns the height of the image.
  4. clear (value ): Clears the entire image by setting each pixel to the given
    intensity value. The intensity value will be clamped to 0 or 255 if it is less
    than 0 or greater than 255, respectively.
  5. getitem (row, col): Returns the intensity level of the given pixel. The
    pixel coordinates must be within the valid range.
  6. setitem (row, col, value): Sets the intensity level of the given pixel to the given value. The pixel coordinates must be within the valid range. The intensity value is clamped to 0 or 255 if it is outside the valid range

Recommended Answers

All 2 Replies

Sounds fairly straightforward. What have you done so far, and where are you stuck?

There is one question I would ask: can you use NumPy homogenous integer arrays, or do you need ot use default lists?

Actually, I have another question: has your coursework covered classes yet? While you can make an Abstract Data Type using just functions and primitive data types such as integers and lists, in Python 'ADT' is generally synonymous with class (or very nearly so). The solution isn't all that different either way, but it would be slightly easier to do it as a class IMAO.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.