My code so far:
#include #include #include #include #include #include #include #include
using namespace std;
bool check(int x, int y, int s){ if (x>=s || y>=s) { return true; }else{ return false; } }
class Count_Pixels { public: vector count_pixels_in_regions(vector > &image, vector, pair > > ®ions); };
int main(){ Count_Pixels pixel_count[]; Count_Pixels image[]; pixel_count[0,0] = image[0,0]; int n = 0; int m = 0;
for (int i=0;i
Anything would help, I'm very lost.
Introduction Given a rectangular region (n x m) in a black and white image, it is easy to count how many pixels are on (1) via a straightforward algorithm that runs in time O(nm) steps. If we want to do this for a number (k) of rectangular regions in a single image, we can save time by preprocessing the image. In particular, if we have k regions, each of size n xn, the straightforward algorithm would take O(k: nn) steps. As described below, we can preprocess the entire n x m image so that counting the number of pixels in the k regions takes only O(n m + k) steps. With this approach, the preprocessing takes O(n.m) steps and computing the pixel count for the k regions taking only O(k) steps, irrespective of the size of the individual regions. Counting White Pixels via Preprocessing Given a black and white (1=white, 0 = black) image of size n x m, it is relatively straight- forward to count how many pixels are on (1) in the region from the origin (pixel 0,0) to any given pixel (i, j). In fact, we can compute all of these values using the following algorithm. pixel_count [0,0] = image [0,0]; for (int i=0;i >. The test harness will also read in a file containing information about a number of regions in the image, and it will store this information in a vector vector, pair > >. Your program (class) will output a vector containing the sum of the on pixels in each region using the approach described above. The prototype for your class is as follows: class Count_Pixels { public: vector count_pixels_in_regions (vector > & image, vector, pair > > ®ions); }; You may add other private or public member functions and data to your class, but do not change the prototype give above. Implement your class using the fast (pre-processing based) algorithm described above. Try to make your code as fast as possible<><>