Ejemplo n.º 1
0
/* This function takes a picture and make from it filled grid. Each element of
 * grid is image`s pixel. Grid is filled with boolean values. If it is a black
 * point, it will be marked as true, other - false.
 */
void imageParsing(string fileName) {
    string fileAdress = "images/";
    fileAdress = fileAdress + fileName;
    GBufferedImage image;
    image.load(fileAdress);
    pixels.resize(image.getWidth(), image.getHeight());
    for (int column = 0; column < image.getWidth(); column++) {
        for (int row = 0; row < image.getHeight(); row++) {
            if (image.getRGB(column, row) <= GREY) {
                pixels.set(column, row, true);
            } else {
                pixels.set(column, row, false);
            }
        }
    }
    for (int column = 0; column < pixels.nCols; column++) {
        for (int row = 0; row < pixels.nRows; row++) {
            if (pixels.inBounds(column, row) && pixels.get(column, row) == true) {
                pixels.set(column, row, false);
                Points blackPoint = makePoint(column, row);
                checkAllNeighbours.push(blackPoint);
                detectingSilouettes(pixels);
            }
        }
    }
}
void silhouetteCount(string nameImageFile){

    int silhouetteCounter=0;
    GImage* imageFile = new GImage(nameImageFile);
    GBufferedImage* imgageInBuffer = new GBufferedImage(0,0,imageFile->getWidth(), imageFile->getHeight());
    imgageInBuffer->load(nameImageFile);

    int imgHaight = imgageInBuffer->getHeight();
    int imgWidth = imgageInBuffer->getWidth();

    GWindow gw(imgWidth, imgHaight);
    gw.add(imageFile);

    myGrid imageBinaring(imgHaight, imgWidth);

    binaringImageToGrid(imgageInBuffer, imageBinaring);
    bool silhouetteIsValid = false;
    for(int x = 0; x < imgHaight; x++){
        for (int y = 0; y < imgWidth; y++){
            if (imageBinaring.get_color(x,y) == true && imageBinaring.get_visited(x,y) == false) {
                selectFindeArea(x,y, imageBinaring, silhouetteIsValid);
                if (silhouetteIsValid) silhouetteCounter++;
            }
        }
    }
    cout<<"in File: "<<nameImageFile<<"; found "<< silhouetteCounter<<" silhouettes."<<endl;
    cout<<endl;

    delete imgageInBuffer;
    delete imageFile;

}
Ejemplo n.º 3
0
/* Depending on how you approach your problem decomposition, you
 * may want to rewrite some of these lines, move them inside loops,
 * or move them inside helper functions, etc.
 *
 * TODO: rewrite this comment.
 */
int main() {
    GWindow gw;
    gw.setTitle("Fauxtoshop");
    gw.setVisible(true);

    cout << "Welcome to Fauxtoshop!" << endl;


    cout << "Enter name of image file to open (or blank to quiet): ";

    string img_name;
    getline(cin, img_name);

    cout << "Opening image file, may take a minute..." << endl;

    GBufferedImage img;
    while (!openImageFromFilename(img, img_name))
    {
        cout << "Can't open the file, please enter again: ";
        getline(cin, img_name);
    }

    gw.setSize(img.getWidth(), img.getHeight());
    gw.add(&img,0,0);

    string menu = "Which image filter would you like to apply?\n"
                  "         1 - Scatter\n"
                  "         2 - Edge detection\n"
                  "         3 - \"Green screen\" with another image\n"
                  "         4 - Compare image with another image";
    cout << menu << endl;

    string choice_str = "Your choice: ";
    int choice = getInteger(choice_str, choice_str);

    switch(choice)
    {
        case 1:
            scatter(img);
            break;
        case 2:
            edge_detection(img);
            break;
        case 3:
            green_screen(img);
            break;
    }


    int row, col;
    getMouseClickLocation(row, col);
    return 0;
}
Ejemplo n.º 4
0
/* Depending on how you approach your problem decomposition, you
 * may want to rewrite some of these lines, move them inside loops,
 * or move them inside helper functions, etc.
 *
 * TODO: rewrite this comment.
 */
int main() {
    GWindow gw;
    gw.setTitle("Fauxtoshop");
    gw.setVisible(true);
    GBufferedImage img;
    while (true) {
        ifstream infile;
        cout << "Welcome to Fauxtoshop!" << endl;
        string prompt = "Enter the name of image file to open (or blank to quit):";
        string filename= openFile(infile, prompt, img);
        if (filename == "") break;
        gw.setSize(img.getWidth(), img.getHeight());
        gw.add(&img,0,0);
        int choice = chooseFilter();
        dealWithImage(img, choice);
        saveImage(img);
    }


    /*int row, col;
    getMouseClickLocation(row, col);*/
    return 0;
}
Ejemplo n.º 5
0
int GBufferedImage::countDiffPixels(GBufferedImage& image) const {
    int w1 = (int) getWidth();
    int h1 = (int) getHeight();
    int w2 = (int) image.getWidth();
    int h2 = (int) image.getHeight();

    int wmin = std::min(w1, w2);
    int hmin = std::min(h1, h2);
    
    int overlap = std::min(w1, w2) * std::min(h1, h2);
    int diffPxCount = (w1 * h1 - overlap) + (w2 * h2 - overlap);

    for (int y = 0; y < hmin; y++) {
        for (int x = 0; x < wmin; x++) {
            int px1 = m_pixels[y][x];
            int px2 = image.m_pixels[y][x];
            if (px1 != px2) {
                diffPxCount++;
            }
        }
    }

    return diffPxCount;
}
Ejemplo n.º 6
0
void gbufferedImageTest() {
    GWindow gw;
    gw.setSize(900, 700);
    gw.setTitle("Test");

    GButton* button1 = new GButton("Click Me 1");
    gw.add(button1, 250, 80);
    //GButton* button2 = new GButton("Click Me 2");
    //gw.addToRegion(button2, "NORTH");

    GLabel* label = new GLabel("test!");
    gw.add(label, 10, 60);
    
    std::cout << "About to construct GBufferedImage." << std::endl;
    GBufferedImage* img = new GBufferedImage(10, 80, 200, 250);
    std::cout << "Done constructing GBufferedImage." << std::endl;
    gw.add(img, 50, 50);
    // gw.addToRegion(img, "SOUTH");
    gw.setVisible(true);
    
//    GBufferedImage* img2 = new GBufferedImage(20, 20);
//    img2->fill(GBufferedImage::createRgbPixel(255, 0, 255));
//    Grid<int> grid = img2->toGrid();
//    cout << "grid of pixels before: " << grid << endl;
//    for (int y = 4; y <= 18; y++) {
//        for (int x = 2; x <= 9; x++) {
//            grid[y][x] = GBufferedImage::createRgbPixel(0, 255, 0);
//        }
//    }
//    cout << "grid of pixels after: " << grid << endl;
//    img2->fromGrid(grid);
//    gw.add(img2, 350, 20);
    
    GBufferedImage* img3 = new GBufferedImage();
    img3->load("rainbow.png");
    cout << "adding the image!" << endl;
    gw.add(img3, 10, 20);
    // pause(2000);
    
    cout << "start toGrid" << endl;
    Grid<int> grid3 = img3->toGrid();
    cout << "end toGrid, start rgb shit" << endl;
    for (int y = 0; y < grid3.height(); y++) {
        for (int x = 0; x < grid3.width(); x++) {
            int red, green, blue;
            GBufferedImage::getRedGreenBlue(grid3[y][x], red, green, blue);
            grid3[y][x] = GBufferedImage::createRgbPixel(green, red, blue);
        }
    }
    cout << "end rgb shit, start fromGrid" << endl;
    img3->fromGrid(grid3);
    cout << "end fromGrid" << endl;
    
    pause(2000);
    return;

    // fill
    img->fill(0xff00ff);  // purple

    std::cout << "About to setRGB on GBufferedImage." << std::endl;
    for (int y = 2; y < img->getHeight() - 2; y++) {
        for (int x = 5; x <= img->getWidth() - 5; x++) {
            img->setRGB(x, y, 0xffcc33);
        }
    }
    std::cout << "Done setting RGB on GBufferedImage." << std::endl;
    border(img);
    pause(500);
    
    std::cout << "About to resize on GBufferedImage." << std::endl;
    img->resize(100, 50);
    border(img);
    pause(500);
    
    std::cout << "About to resize on GBufferedImage." << std::endl;
    img->resize(200, 80);
    border(img);
    pause(500);
    
    std::cout << "About to setRGB on GBufferedImage." << std::endl;
    for (int y = 10; y < img->getHeight() - 10; y++) {
        for (int x = 10; x <= img->getWidth() - 10; x++) {
            img->setRGB(x, y, 0xff33cc);
        }
    }
    border(img);
    
    std::cout << "About to remove other shit." << std::endl;
    pause(200);
    gw.remove(label);
    gw.remove(button1);
    //gw.removeFromRegion(button2, "NORTH");
    pause(200);
    
    std::cout << "About to remove GBufferedImage." << std::endl;
    pause(200);
    gw.remove(img);
    // gw.removeFromRegion(img, "SOUTH");
    pause(200);
    std::cout << "Test complete." << std::endl;
    std::cout << std::endl;
}