80 likes | 189 Views
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:.
E N D
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
Arrays can have 1 or more dimensions… • 1D: • 2D: string dictionary[MAXWORDS]; char board[3][3]; CS 109 -- 10 Mar 2014
Example: Image Processing "grayscale" "invert" "flip horizontal" CS 109 -- 10 Mar 2014
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
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
% 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
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
Next homework: PPM Image Editor PPM Image Editor CS 109 -- 10 Mar 2014