Question

In c++ The iron-puzzle.ppm image is a puzzle; it contains an image of something famous, howeve...

In c++

The iron-puzzle.ppm image is a puzzle; it contains an image of something famous, however the image has been distorted. The famous object is in the red values, however the red values have all been divided by 10, so they are too small by a factor of 10. The blue and green values are all just meaningless random values ("noise") added to obscure the real image. If you were to create a grayscale image out of just the red pixels, you may see the real image, although it is very very dark (way down towards 0 and you do not have to do this). Create a final corrected grayscale image by multiplying each red value by 10, scaling it back up to approximately its proper value and writing it to a .pgm file to create a grayscale image. What is the famous object?

Additional Criteria:

You must modify this program to incorporate functions and pointers.

Write a function called makeDataStructure that reads through the image file and creates a dynamically allocated array. This array contains only the red pixel values. Remember the red pixels are the 1st, 4th, 7th, 10th… numbers in the file. The function will create the array after it reads the first few lines of the .ppm file to determine the size of the image. Therefore, your code should work on an image of any size not just the given one. The function will return the pointer to this dynamically allocated array so it can be accessed from the main function. The function will also use the pass by reference option to give the size of the array to the main function.

Write another function called writeFile that takes the pointer to the dynamically allocated array created by makeDataStructure as a parameter as well as the size of the array then writes the header information and the corrected red values to an output .pgm file. The result will be a grayscale image of our photograph. It will look like a regular black and white photograph when viewed in Irfanview. The function prototypes are given below:

int* makeDataStructure(int &);

void writeFile(int *, int );

0 0
Add a comment Improve this question Transcribed image text
Answer #1

We can try solving this puzzle by using Matlab :

Image1 = imread("image.png");         % To read the given image

[rows, cols, dim] = size(Image1);      % To get the dimention of the image.

figure, imshow(Image1);                   %To display the loaded image

Red_plane = Image1(:,:,1);               % To get only red plane from the original image

figure, imshow(Red_plane);               %To display the Red plane gray scale image

for i=1:rows

    for j=1:cols

        Red_plane(i,j) = Red_plane(i,j) -10;             % Trying to recover the red pixel values according to question

    end;

end;

figure, imshow(Red_plane);         % To display the red plane after applying the changes.

Red_plane1 = Red_plane;

% If we want to make green and blue plane as zeros:

for i=1:rows

    for j=1:cols

        for k=2:dim

            Red_plane1(i,j) = 0;             % Making blue and green values of each pixel as zeros.

        end;

    end;

end;

figure, imshow(Red_plane1);          % Displaying red plane as color image with blue & green plane values are zeros.

% If the values in red plane is divided by 10 then the image pixel value should have a value in between 0-25 but when i checked the value of red plane it is in between 0-255 as usaul in normal image. So the operation must be specified properly which can be easily implemeted in for loop code. Even we can use different filters also based on the type of noise.

Add a comment
Know the answer?
Add Answer to:
In c++ The iron-puzzle.ppm image is a puzzle; it contains an image of something famous, howeve...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • West Image Puzzle The west-puzzle.png image is a puzzle. It shows something famous, however the i...

    West Image Puzzle The west-puzzle.png image is a puzzle. It shows something famous, however the image has been distorted. Use if-logic along with other pixel techniques to recover the true image. The true image is exclusively in the blue values, so set all red and green values to 0. The hidden image is encoded using only the blue values that are less than 16 (that is, 0 through 15). If a blue value is less than 16, multiply it by...

  • Using C programming

    Using C, create a data file with the first number being an integer. The value of that integer will be the number of further integers which follow it in the file. Write the code to read the first number into the integer variable how_many.Please help me with the file :((This comes from this question:Write the code to dynamically allocate ONE integer variable using calloc (contiguous allocation) or malloc (memory allocation) and have it pointed to by a pointer (of type int...

  • 3460:209 Assignment 9-B Assignment9-B: The Element Shifter The purpose of this assignment is to help gauge...

    3460:209 Assignment 9-B Assignment9-B: The Element Shifter The purpose of this assignment is to help gauge your skills in writing small programs that involve pointers. The program also contains functions and may perform input, output, files and file processing, use arrays and vectors and/or c-string/string arrays, flow of control, and/or calculations. PROGRAM SPECIFICATION For this program, we are going to expand a standard array by dynamically allocating a new one with a larger footprint. The program will use a function...

  • Homework Question Write a void function called transformArray that takes two parameters - a reference to...

    Homework Question Write a void function called transformArray that takes two parameters - a reference to a pointer to a dynamically allocated array of ints, and the size of that array.  The pointer is passed by referencebecause you want to change the value of the pointer. The function should dynamically allocate an array that is twice as long, filled with the values from the original array followed by each of those values times 2. For example, if the array that was...

  • Write the code to dynamically allocate ONE integer variable using calloc (contiguous allocation) or malloc (memory...

    Write the code to dynamically allocate ONE integer variable using calloc (contiguous allocation) or malloc (memory allocation) and have it pointed to by a pointer (of type int * ) named ptr_1. Use ptr_1 to assign the number 7 to that dynamically allocated integer, and in another line use printf to output the contents of that dynamically allocated integer variable. Write the code to dynamically allocate an integer array of length 5 using calloc or malloc and have it pointed...

  • (C++) Write a function that accepts an int array and the array’s size as arguments. The function...

    (C++)Write a function that accepts an int array and the array’s size as arguments.The function should create a new array that is twice the size of the argument array.The function should copy the contents of the argument array to the new array, and initialize the unused elements of the second array with 0.The function should return a pointer to the new array.Demonstrate the function by using it in a main program that reads an integer N (that is not more...

  • please write in c++. 4 Derived class JPG 4.1 Class declaration • The class JPG inherits...

    please write in c++. 4 Derived class JPG 4.1 Class declaration • The class JPG inherits from File and is a non-abstract class. 1. Hence objects of the class JPG can be instantiated. 2. To do so, we must override the pure virtual function clone() in the base class. • The class declaration is given below. class JPG : public File { public: JPG(const std::string& n, int n, int w, const double rgb()) : File(...) { // ... } *JPG()...

  • Main topics: Files Program Specification: For this assignment, you need only write a single-file ...

    C program Main topics: Files Program Specification: For this assignment, you need only write a single-file C program. Your program will: Define the following C structure sample typedef struct int sarray size; the number of elements in this sanple's array floatsarray the sample's array of values sample Each sample holds a variable number of values, all taken together constitute a Sample Point Write a separate function to Read a file of delimited Sample Points into an array of pointers to...

  • IN C++ ADD COMMENTS AS MUCH AS POSSIBLE Exercise 1: Duplicate the Arrays Suppose you are...

    IN C++ ADD COMMENTS AS MUCH AS POSSIBLE Exercise 1: Duplicate the Arrays Suppose you are developing a program that works with arrays of integers, and you find that you frequently need to duplicate the arrays. Rather than rewriting the array-duplicating code each time you need it, you decide to write a function that accepts an array and its size as arguments. Creates a new array that is a copy of the argument array, and returns a pointer to the...

  • 9.10: Reverse Array Write a function that accepts an int array and the array’s size as arguments

    9.10: Reverse Array Write a function that accepts an int array and the array’s size as arguments. The function should create a copy of the array, except that the element values should be reversed in the copy. The function should return a pointer to the new array. Demonstrate the function by using it in the main program that reads an integer N  (that is not more than 50) from standard input and then reads N  integers from a file named...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT