1 / 8

Administrative HW 7 due tonight , March 10 th @ 9pm Quick look at calendar… Today?

Administrative HW 7 due tonight , March 10 th @ 9pm Quick look at calendar… Today? 1D and 2D arrays Image processing PPM Image Editor. CS 109 C/C++ Programming for Engineers with MATLAB. HW7. HW9. MID. HW8. Arrays can have 1 or more dimensions … 1D: 2D:.

karik
Download Presentation

Administrative HW 7 due tonight , March 10 th @ 9pm Quick look at calendar… Today?

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Administrative • HW 7 due tonight, March 10th @ 9pm • Quick look at calendar… • Today? • 1D and 2D arrays • Image processing • PPM Image Editor CS 109 C/C++ Programming for Engineers with MATLAB HW7 HW9 MID HW8 CS 109 -- 10 Mar 2014

  2. Arrays can have 1 or more dimensions… • 1D: • 2D: string dictionary[MAXWORDS]; char board[3][3]; CS 109 -- 10 Mar 2014

  3. Example: Image Processing "grayscale" "invert" "flip horizontal" CS 109 -- 10 Mar 2014

  4. Image Processing == 1D and 2D array processing width pixel == Red Green Blue height 2D array of pixels black: 0 0 0 white:255 255 255 red:255 0 0 green:0 255 0 blue:0 0 255 purple:128 0 128 yellow:255 255 0 . . CS 109 -- 10 Mar 2014

  5. Quiz 7: • percentage of black pixels in a given row… RGB double BlackPixelPercentage(int row[MAX], int width) { int N, count; N = width * 3; // 3 integers per pixel (RGB) count = 0; for (intc = 0; c < N; c=c+3) // count across by index of Red: 0, 3, 6, ... { if (row[c] == 0 && row[c+1] == 0 && row[c+2] == 0) // color black: { count = count + 1; } } double percentage; percentage = ((double) count / (double) width) * 100.0; return percentage; } for (intp = 0; p < width; p=p+1) // count by pixels: 0, 1, 2, … { R = p * 3; // index of Red for pixelp: if (row[R] == 0 && row[R+1] == 0 && row[R+2] == 0) { count = count + 1; } } CS 109 -- 10 Mar 2014

  6. % black pixels in an entire image? 2D double BlackPixelPercentage(intimage[MAXROWS][MAXCOLS], intheight, intwidth) { introws, cols, count; rows = height; cols = width * 3; // 3 integers per pixel (RGB) count = 0; for (int r = 0; r < rows; r=r+1) // for each row of image: { for (intc = 0; c < cols; c=c+3) // count across by index of Red: 0, 3, 6, ... { if (row[r][c] == 0 && row[r][c+1] == 0 && row[r][c+2] == 0) // RGB == black: { count = count + 1; } } } double percentage; percentage = ((double) count / (double) (height*width)) * 100.0; return percentage; } CS 109 -- 10 Mar 2014

  7. Case study: PPM Image File format • human-readable text file • can open in any text editor • not very efficient, but easy to work with file format width height max color value ("depth") CS 109 -- 10 Mar 2014

  8. Next homework: PPM Image Editor PPM Image Editor CS 109 -- 10 Mar 2014

More Related