Question

O https//maryash.github.io/135/labs/lab 08 html Since the program should work for all input images that fit into the array, d
O hmps//maryash github 1o/135/labs/lab 08 html Task E. Scale 200% Program scale.cpp Scale the ongnal picture to 200% of its s
С Ohttps://maryash githubionasatsab08 html -) Task F. Pixelate Program pixelate.cpp wil be pixelating the input image Example
e С https://mtaryashgthuba135Aabuab.08html Task F. Pixelate Program pixelate.cpp will be pixelating the input image Example w
C htts/maryash.github io/135/ labs/ab 08.hml 12 22 32 42 13 23 33 43 should be transformed to 16 16 36 36 16 16 36 36 18 18 3
(--) С http://maryashgthub iar sabsab08 html Task G (Bonus). Kernel method image fitering A siding window operator replaces e
> С https://maryash.gthubio/13sabsab,08 html For this task, write a program kernel.cpp which implements a horizontal edge det
(--) С Ф httpt//m aryashgthubitsabslab 08 henl 30 Remark 1 Nobe that this is a sliding window operator unlke the non-overlappc++

solve each task please
O https//maryash.github.io/135/labs/lab 08 html Since the program should work for all input images that fit into the array, don't Thard-code" the cat picture dimensions into the program, use variables w and h instead Task D. One-pixethick frame Program frame.cpp Same as the previous task, but it should be a frame exactly one pixel thick Example: Task E. Scale 200% Program scale.cpp Scale the original picture to 200% of its size. It can be done by increasing the ere to search Dll dx d) Prt Scn,, 18 Home End
O hmps//maryash github 1o/135/labs/lab 08 html Task E. Scale 200% Program scale.cpp Scale the ongnal picture to 200% of its size. It can be done by increasing the sze of the picture by the factor of 2, and copying each pixel of the input as a small 2x2 square in the output. (We don't do any interpolation of colors as more advanced scaling procedures would do.) 11 22 33 44 11 11 22 22 11 11 22 22 33 33 44 44 33 33 44 44 Example O Type here to search di do Prt Scn Home p EndPg 5 6
С Ohttps://maryash githubionasatsab08 html -) Task F. Pixelate Program pixelate.cpp wil be pixelating the input image Example 0 Type here to search 4 PrtScn Home EndPgUp 5 6
e С https://mtaryashgthuba135Aabuab.08html Task F. Pixelate Program pixelate.cpp will be pixelating the input image Example way to pixelate an image is to eflectively make every 2x2 non-overlapping window same value (averaged over all the pixels in that window ot the input) For example, the following contain the 18 28 38 40 11 21 31 41 12 22 32 42 13 23 33 43 should be transformed to 16 16 36 36 O Type here to search Prt Scn Home End PUp w 6 0 WE TY U IOP
C htts/maryash.github io/135/ labs/ab 08.hml 12 22 32 42 13 23 33 43 should be transformed to 16 16 36 36 16 16 36 36 18 18 37 37 18 18 37 37 where the 16 was computed by averaging 10, 20, 11, and 21 (after rounding), and so on For simplicity, assume that the width and the height of the image are even numbers, so the picture is divisible into small 2x2 squares, like in the example above. Task o (eonus) Kamal mothod image fitorng A siliding window operator replaces each pixel with some function of its 8 neighbors (and itselt) Consider pixel and its 8 neighbors (labeled a i ) that form a 3x3 window around it. abe O Type here to search Prt Scns End vo 4 6 8 WE R
(--) С http://maryashgthub iar sabsab08 html Task G (Bonus). Kernel method image fitering A siding window operator replaces each pixel with some function of its 8 neighbors (and itsei) Consider prel e and its 8 neighbors (labeled a-i ) that form a 3x3 window around it ts neighbors (abeledyhat form a bc .def. 8 hi. The operation replaces pixele (in the middle of the 3x:3 window) with some function of its neighbors fa,b,c,d,e,f.g.h,1) It is possible to implement blur, edge detection, and many other image processing operations using this technique References Lode's Computer Grarhics Tiaerial image Filtering For this task, winite a program kerne1.cpp which implements a horizontal edge detection operation. One way to detect horizontal edges is to use the function Type here to search Prt Scn Home 2 6 8 WIE
> С https://maryash.gthubio/13sabsab,08 html For this task, write a program kernel.cpp which implements a horizontal edge detection operation. One way to detect horizontal edges is to use the function f(a,b,c,d,e,f,g,h,i)(8+2h+1)-(a+2b+c) (This is one component of the so called Sobel operator, if you want to read more aboutis Remark 1 Note that this is a sliding window operator unlike the non-overlapping window pixelization operator in the previous task. That is, the considered window is always a window whose value is being computed around the pixel 2 You shouldn't overwnite the original array. Make a new array for the output, and write the resulting pixel color into the new array Remark 3: There are Type here to search Prt Scn Home End Pak 5 6 9 W I
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Task F

#include <iostream>

#include <cassert>

#include <cstdlib>

#include <fstream>

using namespace std;

const int MAX_H = 512;

const int MAX_W = 512;

// Reads a PGM file.

// Notice that: height and width are passed by reference!

void readImage(int image[MAX_H][MAX_W], int &height, int &width) {

char c;

int x;

ifstream instr;

instr.open("inImage.pgm");

// read the header P2

instr >> c;

assert(c == 'P');

instr >> c;

assert(c == '2');

// skip the comments (if any)

while ((instr>>ws).peek() == '#') {

instr.ignore(4096, '\n');

}

instr >> width;

instr >> height;

assert(width <= MAX_W);

assert(height <= MAX_H);

int max;

instr >> max;

assert(max == 255);

for (int row = 0; row < height; row++)

for (int col = 0; col < width; col++)

instr >> image[row][col];

instr.close();

return;

}

// Writes a PGM file

// Need to provide the array data and the image dimensions

void writeImage(int image[MAX_H][MAX_W], int height, int width) {

ofstream ostr;

ostr.open("outImage.pgm");

if (ostr.fail()) {

cout << "Unable to write file\n";

exit(1);

};

// print the header

ostr << "P2" << endl;

// width, height

ostr << width << ' ';

ostr << height << endl;

ostr << 255 << endl;

for (int row = 0; row < height; row++) {

for (int col = 0; col < width; col++) {

assert(image[row][col] < 256);

assert(image[row][col] >= 0);

ostr << image[row][col] << ' ';

ostr << endl;

}

}

ostr.close();

return;

}

int main() {

int img[MAX_H][MAX_W];

int h, w;

int avg = 0;

readImage(img, h, w); // read it from the file "inImage.pgm"

// h and w were passed by reference and

// now contain the dimensions of the picture

// and the 2-dimesional array img contains the image data

// Now we can manipulate the image the way we like

// for example we copy its contents into a new array

int out[MAX_H][MAX_W];

for(int row = 0; row < h; row++) {

for(int col = 0; col < w; col ++) {

avg = (out[row][col] + out[row][col + 1] + out[row + 1][col] + out[row + 1][col + 1])/4; // find ave

out[row][col] = out[row][col + 1] = out[row + 1][col] = out[row + 1][col + 1] = avg;

col += 2; // skip a col

row += 2; // skip a row

}

}

// and save this new image to file "outImage.pgm"

writeImage(out, h, w);

}

Add a comment
Know the answer?
Add Answer to:
O https//maryash.github.io/135/labs/lab 08 html Since the program should work for all input image...
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
  • NB: All C programs should be compiled using C Compiler application. The code should be shown...

    NB: All C programs should be compiled using C Compiler application. The code should be shown on the document. A screen shot of the running program given as output on the assignment. a). Describe the types of arrays and operations that can be performed of them. [10] b). Write a program to print the multiplication table from 1*1 to 12*10. [10] Example MULTIPLICATION TABLE 1 2 3 4 5 6 7 8 9 10 2 4 6 8 10 12...

  • HTML Text Query All La Edit Links X & fx 844 STION C2 A B C...

    HTML Text Query All La Edit Links X & fx 844 STION C2 A B C D E F s the date 1 Highway ataset ab 2 uct a 5% F 3 ANOVA, 5 6 4 Gas Conven 952 1298 844 996 1195 921 839 1174 880 1088 1113 706 1024 953 602 1280 614 7 Τ Τ + 8 9 10 11 Mashups 12 13 14 15 16 17 18 19 Path: P 20 21 22 23 24 25...

  • Please show how you did this in excel. :13-19 Every home football game for the past...

    Please show how you did this in excel. :13-19 Every home football game for the past eight years at Eastern State University has been sold out. The revenues from ticket sales are significant, but the sale of food, beverages, and souvenirs has contrib- uted greatly to the overall profitability of the football program. One particular souvenir is the football pro- gram for each game. The number of programs sold at each game is described by the following probabil- ity distribution:...

  • Programming Exercise 8.3 | Instructions Write a GUI-based program that allows the user to convert temperature...

    Programming Exercise 8.3 | Instructions Write a GUI-based program that allows the user to convert temperature values between degrees Fahrenheit and degrees Celsius. The interface should have labeled entry fields for these two values. breezypythongui.py temperatureconvert... + 1 2 File: temperatureconverter.py 3 Project 8.3 4 Temperature conversion between Fahrenheit and Celsius. 5 Illustrates the use of numeric data fields. 6 • These components should be arranged in a grid where the labels occupy the first row and the corresponding fields...

  • this is c code. please answer all questions on a piece of paper and show work....

    this is c code. please answer all questions on a piece of paper and show work. i need to prepare as i have a midterm i will have to be completing on paper 1) Bit Operators: This C program compiles and runs. What is its output? 1) #include <stdio.h> 2) void main (void) 3) unsigned char x =60; 4) 5) 6) 7) 8 ) 9) 10) 11) 12) 13) unsigned char a = x < 1; unsigned char b unsigned...

  • I posted this question earlier but realized that the code was not easy to test since...

    I posted this question earlier but realized that the code was not easy to test since it was just screenshots and not text so I am reposting it: I'm very new at working with file streams, and I'm having trouble with a HW assignment I have to work on. For the assignment I have to read an input file named "MagicSquaresIn.txt" (included at the bottom) and I have to check whether they are normal, associative, and panmagic. To check that...

  • Instructions CheckZips.cs + >_ Terminal Write a program named CheckZips that is used by a package...

    Instructions CheckZips.cs + >_ Terminal Write a program named CheckZips that is used by a package delivery service to check delivery areas. 1 using static System.Console; 2 class CheckZips 3 { 4 static void Main() 5 { 6 string[] zips = {"12789", "54012", "54481", "54982", "60007", "60103", "60187", "60188", "71244", "90210"}; CheckZips.cs(10,8): error CS002 9: Cannot implicitly convert ty pe 'string' to 'string[]' CheckZips.cs(18,5): error CS001 9: Operator '==' cannot be appl ied to operands of type 'string []' and...

  • Please show all work and explain here is the data and explanation of 12.4 here is appendix D

    please show all work and explain here is the data and explanation of 12.4 here is appendix D 12.12. * In Problem 12.4, find the value of x2. If the dice really are true, what is the probability of getting a value of X2this large or larger? Explain whether the evidence suggests the dice are loaded. (See Appendix D for the necessary probabili- ties.) 12.4.I throw three dice together a total of 400 times, record the number of sixes in...

  • Write a Python program (question2.py) that reads from a file called “input.txt” numbers in [1,39] separated...

    Write a Python program (question2.py) that reads from a file called “input.txt” numbers in [1,39] separated in by commas. The numbers are in [1-99]. The program will then convert each number to a possible Roman Numeral equivalent, and print it on the screen. Remember, I is 1, V is 5, X is 10 For example, if the input is: 23, 11 the output is: XXIII, XI. ROMAN NUMERALS CHART 1 TO 100 69 LXIX 11 2 11 3 III 4...

  • Complete function long_list_printer.print_list(). When it's finished, it should be able to print this list, a =...

    Complete function long_list_printer.print_list(). When it's finished, it should be able to print this list, a = [ [93, 80, 99, 72, 86, 84, 85, 41, 69, 31], [15, 37, 58, 59, 98, 40, 63, 84, 87, 15], [48, 50, 43, 68, 69, 43, 46, 83, 11, 50], [52, 49, 87, 77, 39, 21, 84, 13, 27, 82], [64, 49, 12, 42, 24, 54, 43, 69, 62, 44], [54, 90, 67, 43, 72, 17, 22, 83, 28, 68], [18, 12, 10,...

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