예제 #1
0
    /**
     * @param image
     * @return out3
     */
    public image synthesize(image img)
    {
        //        BufferedImage copie = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_INT_ARGB);
        //        copie = CubeImage.getAsCopy(image);
        image copie = new image(img);

        _in = duplicateSample(copie);

        //Nb de patch par ligne et par colonne
        _nbPatchPerLine   = _widthFinalTexture  / (_patchSize-_widthBorder) +1;
        _nbPatchPerColumn = _heightFinalTexture / (_patchSize-_widthBorder) +1;

        _nbPatchPasted = 1;
        nbLinesDone    = 0;

        _widthAnalysis  = _in.Width()  - _patchSize;
        _heightAnalysis = _in.Height() - _patchSize;

        //Initialisation de Out
        //        BufferedImage out = new BufferedImage((_nbPatchPerLine)*(_patchSize-_widthBorder)+_widthBorder, (_nbPatchPerColumn)*(_patchSize-_widthBorder)+_widthBorder, BufferedImage.TYPE_INT_ARGB);
        image outImg = new image((_nbPatchPerLine)*(_patchSize-_widthBorder)+_widthBorder,
                                 (_nbPatchPerColumn)*(_patchSize-_widthBorder)+_widthBorder);
        System.Random r = new System.Random();
        //        int x = r.nextInt(_widthAnalysis);
        //        int y = r.nextInt(_heightAnalysis);
        int x = r.Next(_widthAnalysis);
        int y = r.Next(_heightAnalysis);

        //        BufferedImage firstPatch = _in.getSubimage(x, y, _patchSize, _patchSize);
        image first_patch = _in.getSubImage(x, y, _patchSize, _patchSize);

        //        out.getGraphics().drawImage(firstPatch, 0, 0, null);
        outImg.setPixels(first_patch);

        analyseIn(_in);

        for(int i=0; i<_nbPatchPerLine-1; i++)
            firstLine(_in, outImg);

        for(int i=0; i<_nbPatchPerColumn-1; i++)
        {
            nbLinesDone++;
            firstPatch(_in, outImg);
            _nbPatchPasted = 1;

            for(int k=0; k<_nbPatchPerLine-1; k++)
                otherLine(_in, outImg);
        }
        //        out = out.getSubimage(0, 0, _widthFinalTexture, _heightFinalTexture);
        outImg = outImg.getSubImage(0, 0, _widthFinalTexture, _heightFinalTexture);

        //        BufferedImage out2 = new BufferedImage(2*_widthFinalTexture, 2*_heightFinalTexture, BufferedImage.TYPE_INT_ARGB);
        image out2 = new image(2*_widthFinalTexture, 2*_heightFinalTexture);
        //        out2.getGraphics().drawImage(out, 0, 0, null);
        out2.setPixels(outImg);
        //        out2.getGraphics().drawImage(out, _widthFinalTexture, 0, null);
        out2.setPixels(outImg, _widthFinalTexture, 0);
        //        out2.getGraphics().drawImage(out, 0, _heightFinalTexture, null);
        out2.setPixels(outImg, 0, _heightFinalTexture);
        //        out2.getGraphics().drawImage(out, _widthFinalTexture, _heightFinalTexture, null);
        out2.setPixels(outImg, _widthFinalTexture, _heightFinalTexture);

        //        BufferedImage out3 = new BufferedImage(4*_widthFinalTexture, 4*_heightFinalTexture, BufferedImage.TYPE_INT_ARGB);
        image out3 = new image(4*_widthFinalTexture, 4*_heightFinalTexture);
        //        out3.getGraphics().drawImage(out2, 0, 0, null);//out2
        out3.setPixels(out2, 0, 0);//out2
        //        out3.getGraphics().drawImage(out2, 2*_widthFinalTexture, 0, null);
        out3.setPixels(out2, 2*_widthFinalTexture, 0);
        //        out3.getGraphics().drawImage(out2, 0, 2*_heightFinalTexture, null);
        out3.setPixels(out2, 0, 2*_heightFinalTexture);
        //        out3.getGraphics().drawImage(out2, 2*_widthFinalTexture, 2*_heightFinalTexture, null);
        out3.setPixels(out2, 2*_widthFinalTexture, 2*_heightFinalTexture);
        return out3;
    }
예제 #2
0
    //-----------------------------------------------------
    // Fonction qui génère une image 4 fois plus grande que l image d entrée
    // en effectuant des miroirs par rapport à l image d entrée
    //  @param image L'image d entrée
    //  @return duplicateImage L'image dupliquée
    //    private BufferedImage duplicateSample(BufferedImage image)
    private image duplicateSample(image img)
    {
        int[] rgb  = new int[(_sampleSize/2)*(_sampleSize/2)];
        //        rgb = image.getRGB(_sampleSize/2, _sampleSize/2, rgb, 0, _sampleSize/2);
        rgb = img.getRGB(rgb);

        rgb = removeArtifacts(rgb);         // enlève les pixels trop eloignés de la moyenne du sample

        //        image.setRGB(0, 0, _sampleSize/2, _sampleSize/2, rgb, 0, _sampleSize/2);
        img.setRGB(rgb);                  // image sans artefacts

        // -- Miroir par rap à Y --
        //        BufferedImage _inYmirror = new BufferedImage(_sampleSize/2, _sampleSize/2, BufferedImage.TYPE_INT_ARGB);
        image _inYmirror = new image(img); // Copie
        _inYmirror.MirrorY();

        //        BufferedImage _in4 = new BufferedImage(2*image.getWidth(), image.getHeight(), BufferedImage.TYPE_INT_ARGB);
        image _in4 = new image(2*img.Width(), img.Height());
        //        _in4.getGraphics().drawImage(image, 0, 0, null);
        _in4.setPixels(img);
        //        _in4.getGraphics().drawImage(_inYmirror, _in4.getWidth()/2, 0, null);
        _in4.setPixels(_inYmirror, _in4.Width()/2, 0);        // TODO Vérifier si le résultat est correct

        // -- Miroir par rap à X --
        //        BufferedImage in5 = new BufferedImage(_sampleSize, _sampleSize/2, BufferedImage.TYPE_INT_ARGB);
        image in5 = new image(_in4);
        in5.MirrorX();

        //        BufferedImage duplicateImage = new BufferedImage(_sampleSize, _sampleSize, BufferedImage.TYPE_INT_ARGB);
        image duplicateImage = new image(_sampleSize, _sampleSize);
        //        duplicateImage.getGraphics().drawImage(_in4, 0, 0, null);
        duplicateImage.setPixels(_in4);
        //        duplicateImage.getGraphics().drawImage(in5, 0, _sampleSize/2, null);
        duplicateImage.setPixels(in5, 0, _sampleSize/2);

        return duplicateImage;
    }