Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

For this lab, you will do some basic manipulations of gray-scale images. The obvious data structure for an image is a 2-D array, so you

For this lab, you will do some basic manipulations of gray-scale images. The obvious data structure for an image is a 2-D array, so you will be writing functions that manipulate 2-D arrays.

    TASKS

    For all tasks:

    There are many image formats (jpg, png, etc.), and we will use PGM (Portable GrayMap) since it is a simple grayscale format.

    You may need to use the following linux programs while developing your programs.

    • Viewing a PGM image: eog and gimp are standard Linux program for viewing images in various formats.
    • Converting between image formats: The Linux utility convert will convert between all standard formats, where its 2 arguments are the input and output files, with format determined by filename suffix. You won't need this unless you want to play with other image formats.

    We need a way to convert gray-scale images to arrays, and output arrays into image files. Your instructor will supply you two functions as follows:

    • writeImage: writes the argument image (a 2-D array) to outImage.pgm in PGM grayscale format.
    • readImage: reads a PGM grayscale format from inImage.pgm into an array, and updates the height/width arguments appropriately (since they are passed by reference).

    You may use these functions as is.

    Task 0:

    First, we need a gray-scale image to work on. Save the one supplied by your instructor to $PWD. This file format has 8-bit images - i.e., each pixel is a gray scale value between 0 and 255 inclusive.

    Since all our tasks will involve reading an image file, processing the image, and writing the processed image back to a different file, we will first get the basics setup. Write a small program that uses the given readimage/writeimage functions to input the PPM file into an array, copies the image to a 2nd array, and writes the 2nd array back. View the resulting image to make sure its the same as the original image.

    Task 1:
    One way to highlight objects in an image is to make all pixels below a threshold (t1) 0, and all pixels above a threshold (t2) 255. Write a function to highlight the image, using the following prototype: void highlight(int image[][MAXHEIGHT],int width, int height, int t1, int t2) Write a main program that inputs t1 and t2 from the user, highlights the image, and then writes the image. This highlighting is called segmentation, though most segmentation algorithms are much more complicated.
    Task 2:

    One way to pixelate an image is to effectively make every nXn non-overlapping window contain the same value (the obvious value is the average of the window). For example, if n=2, the following image:

    10 20 30 40 11 21 31 41 12 22 32 42 13 23 33 43
    may be transformed to: 16 16 36 36 16 16 36 36 18 18 37 37 18 18 37 37 Repeat the earlier tasks, except with a function named scale. Your function should work for arbitrary values of n, though you are free to simplify your work by defining arbitrary behaviors for the problematic values of n (I suggest you define such behaviors to be whatever falls out of your code). But make sure to state in comments how you handle any problematic values for n.
    Task 3:

    A sliding window operator replaces each pixel with some function of its 8 neighbors (and itself). Consider the following 3X3 window:

    a b c d e f g h i
    Then, pixel e would be replaced by some function f(a,b,c,d,e,f,g,h,i). One way to detect horizontal edges is to use the function (g+2h+i)-(a+2b+c). Note that this is a sliding windowoperator unlike the non-overlapping windows in the previous task - that is, the window is always a window around the pixel whose value is being computed. Write a horizontal edge detection function, named hEdgeDet. For the top/bottom rows and left/right columns of the image, you should assume a wrap-around - for example, if the image has width 64 and you are determining the value of the pixel at column 0 row 14, the d argument would be the pixel at column 63 row 14.

    Step by Step Solution

    There are 3 Steps involved in it

    Step: 1

    blur-text-image

    Get Instant Access to Expert-Tailored Solutions

    See step-by-step solutions with expert insights and AI powered tools for academic success

    Step: 2

    blur-text-image

    Step: 3

    blur-text-image

    Ace Your Homework with AI

    Get the answers you need in no time with our AI-driven, step-by-step assistance

    Get Started

    Recommended Textbook for

    Database Concepts

    Authors: David M. Kroenke

    1st Edition

    0130086509, 978-0130086501

    More Books

    Students also viewed these Databases questions