예제 #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
    /**
      * Les lignes suivantes
      * @param in
      * @param out
      */
    private void otherLine(image imgIn, image imgOut)
    {
        int[] rgbOutH = new int[_widthBorder*_heightBorder];
        //Pour les bords du haut
        int[] rgbOutW = new int[_widthBorder*_heightBorder];

        int[] rgbOutHD = new int[_widthBorder*_heightBorder];

        //Tableau qui contiendra toutes les distances (en se positionnant en chaque point de In)
        float[] tabDistanceH = new float[_widthAnalysis*_heightAnalysis];
        float[] tabDistanceW = new float[_widthAnalysis*_heightAnalysis];

        float[] tabDistanceHD = new float[_widthAnalysis*_heightAnalysis];
        //Liste qui contiendra les index (numeros de pixels) dont la distance avec le dernier patch collé est
        //inferieure à la distance max
        float[] tabDistInf  = new float[200];
        int[] tabDistInfIndex  = new int[tabDistInf.Length];

        for (int i = 0; i < tabDistInf.Length; i++)
        {
            tabDistInf[i] = float.MaxValue;
            tabDistInfIndex[i] = -1;
        }

        //Les valeurs rgb du bord de _out (à droite)

        //        out.getRGB(((_nbPatchPasted)*(_patchSize-_widthBorder)),  nbLinesDone*(_patchSize-_widthBorder), _widthBorder, _heightBorder, rgbOutH, 0, _widthBorder);
        imgOut.getRGB(rgbOutH, ((_nbPatchPasted)*(_patchSize-_widthBorder)),
                      nbLinesDone*(_patchSize-_widthBorder), _widthBorder, _heightBorder);
        //        out.getRGB(0,  nbLinesDone*(_patchSize-_widthBorder), _widthBorder, _heightBorder, rgbOutHD, 0, _widthBorder);
        imgOut.getRGB(rgbOutHD, 0,  nbLinesDone*(_patchSize-_widthBorder), _widthBorder, _heightBorder);

        //Les valeurs rgb du bord de out (en bas)
        //        out.getRGB((_nbPatchPasted)*(_patchSize-_widthBorder), nbLinesDone*(_patchSize-_widthBorder), _heightBorder, _widthBorder, rgbOutW, 0, _heightBorder);
        imgOut.getRGB(rgbOutW, (_nbPatchPasted)*(_patchSize-_widthBorder),
                      nbLinesDone*(_patchSize-_widthBorder), _heightBorder, _widthBorder);

        float dMax = 0;
        if(_nbPatchPasted == _nbPatchPerLine-1)
            dMax = get_dMax(rgbOutH) + get_dMax(rgbOutW) + get_dMax(rgbOutHD);
        else
            dMax = get_dMax(rgbOutH) + get_dMax(rgbOutW);

        int index = 0;
        int distMin = int.MaxValue;
        int indexMin = int.MaxValue;

        //Parcours de l image (moins les deux bords en bas et à droite)
        for (int i=0; i<_widthAnalysis*_heightAnalysis; i+=_pasBalayage)
        {
            //L ensemble des distances en positionnant le patch sur chaque pixel de l image
            tabDistanceH[index]  = distance(_tabInH[index], rgbOutH);

            tabDistanceHD[index] = distance(_tabInHD[index], rgbOutHD);

            tabDistanceW[index]  = distance(_tabInW[index], rgbOutW);

            //On fait la somme des deux distances
            tabDistanceW[index] += tabDistanceH[index];

            if(_nbPatchPasted == _nbPatchPerLine-1)
                tabDistanceW[index] += tabDistanceHD[index];

            if(tabDistanceW[index] < dMax)
            {
                float distmax = -1;
                int indexTabdistInf = -1;

                for(int k=0; k<tabDistInf.Length; k++)
                {
                    if(tabDistanceW[index] < tabDistInf[k])
                    {
                        if(tabDistInf[k] > distmax)
                        {
                            distmax = tabDistInf[k];
                            indexTabdistInf = k;
                        }
                    }
                }
                if(indexTabdistInf!=-1)
                {
                    tabDistInfIndex[indexTabdistInf] = index;
                    tabDistInf[indexTabdistInf] = tabDistanceW[index];
                }
            }

            //Distance min
            if(tabDistanceW[index]<distMin)
            {
                distMin = (int)tabDistanceW[index];
                indexMin = index;
            }
            index=index+_pasBalayage;
        }

        //On ajoute la plus petite distance si aucune n etait inférieure à  dMax
        int l = 0;
        while(l<tabDistInf.Length && tabDistInfIndex[l]!=-1) l++;

        if(tabDistInf[0]==float.MaxValue)   //tableau vide
        {
            tabDistInf[0] = distMin;
            tabDistInfIndex[0] = indexMin;
            l = 1;
        }

        //Un index dans la liste des distance inférieures au seuil (aleatoirement)
        System.Random r = new System.Random();
        int random = r.Next(l);

        //On copie le patch choisi aleatoirement dans l image out
        //        Graphics2D g2d = (Graphics2D)out.getGraphics();
        //Le patch qu on colle dans Out
        image patch = null;

        patch = imgIn.getSubImage((tabDistInfIndex[random]%_widthAnalysis),
                                tabDistInfIndex[random]/_widthAnalysis, _patchSize, _patchSize);

        //Le tableau de pix du bord du patch
        int[] rgbPatchBorderH = new int[_patchSize*_patchSize];
        int[] rgbPatchBorderW = new int[_patchSize*_patchSize];
        //        patch.getRGB(0, 0, _widthBorder, _heightBorder, rgbPatchBorderH, 0, _widthBorder);
        patch.getRGB(rgbPatchBorderH, 0, 0, _widthBorder, _heightBorder);
        //        patch.getRGB(0, 0, _heightBorder, _widthBorder, rgbPatchBorderW, 0, _heightBorder);
        patch.getRGB(rgbPatchBorderW, 0, 0, _heightBorder, _widthBorder);

        //On colle le patch par dessus le dernier patch collé dans Out
        //        g2d.drawImage(patch,_nbPatchPasted*(_patchSize-_widthBorder),  nbLinesDone*(_patchSize-_widthBorder), null);
        imgOut.setPixels(patch, _nbPatchPasted*(_patchSize-_widthBorder), nbLinesDone*(_patchSize-_widthBorder));

        //On arrange la liaison entre les deux patch
        //        out = borderH(rgbOutH, rgbPatchBorderH, out);
        imgOut = borderH(rgbOutH, rgbPatchBorderH, imgOut);
        //        out = borderW(rgbOutW, rgbPatchBorderW, out, false);
        imgOut = borderW(rgbOutW, rgbPatchBorderW, imgOut, false);

        _nbPatchPasted++;
    }