[JAVA] Bureau: OpenCV Dft

Goal
Test OpenCV Dft.

OpenCV_Dft.java


package Ch14;

import org.opencv.core.*;
import org.opencv.imgcodecs.Imgcodecs;

import java.util.ArrayList;
import java.util.List;

public class OpenCV_Dft {
    static {System.loadLibrary(Core.NATIVE_LIBRARY_NAME);};

    public static void main( String[] args )
    {
        try{
            Mat source = Imgcodecs.imread("D:\\projects\\Java\\OpenCV_Samples\\resource\\imgs\\lena.jpg ",Imgcodecs.CV_LOAD_IMAGE_GRAYSCALE);

            /////////////part1 optimizeImageDim
            // optimize the dimension of the loaded image
            // init
            Mat padded=new Mat();
            // get the optimal rows size for dft
            int addPixelRows = Core.getOptimalDFTSize(source.rows());
            // get the optimal cols size for dft
            int addPixelCols = Core.getOptimalDFTSize(source.cols());
            // apply the optimal cols and rows size to the image

            //La vitesse de calcul est la meilleure lorsque l'échelle est ajustée 2, 3 et 5 fois. Calcul rapide,
            //將 Statue importée Arrivée de l'exposition Kabuki La meilleure échelle,Élément d'image additif pour l'initialisation 0
            Core.copyMakeBorder(source, padded, 0, addPixelRows - source.rows(), 0, addPixelCols - source.cols(),1, Scalar.all(0));
            // return padded;
            //end part1 optimizeImageDim
            //System.out.println(padded.dump());

            //main
            //Distribuer Tachibana Convertible Minabe Kazuobu Espace rentable 兩 Individuel 圖 Statue 值.傅 Résultat de conversion Tachiba multiple, cause cette très petite quantité de type flottant d'existence de profit de zone fréquente, montant moyen numéro un en dehors du passage 來 Partie composée d'existence de profit:
            padded.convertTo(padded, CvType.CV_32F);
            List<Mat> planes = new ArrayList<Mat>();
            Mat complexImage=new Mat();
            // prepare the image planes to obtain the complex image
            planes.add(padded);
            planes.add(Mat.zeros(padded.size(), CvType.CV_32F));

            // prepare a complex image for performing the dft
            ////Post-exposition de l'exposition
            Core.merge(planes, complexImage);
            // dft
            //Conversion discrète progressive de Tachiba,Le résultat de la conversion existe Primitive Mat Rokujin
            Core.dft(complexImage, complexImage);
            //Mat magnitude = new Mat();

            // optimize the image resulting from the dft operation
            /// part2 createOptimizedMagnitude
            // init

            List<Mat> newPlanes = new ArrayList<Mat>();
            Mat mag = new Mat();
            // split the comples image in two planes
            //將 Degré d'arc de conversion multiple.
            Core.split(complexImage, newPlanes);
            // compute the magnitude
            Core.magnitude(newPlanes.get(0), newPlanes.get(1), mag);
            // move to a logarithmic scale
            //Balance convertible
            Core.add(mag, Scalar.all(1), mag);
            Core.log(mag, mag);
            // optionally reorder the 4 quadrants of the magnitude image
            ////////////////part3 shiftDFT
            //Ligne de coupe et excentrique
            mag = mag.submat(new Rect(0, 0, mag.cols() & -2, mag.rows() & -2));

            //Division lourde 彈 傅 Largeur de vantail debout 4 quadrants
            int cx = mag.cols() / 2;
            int cy = mag.rows() / 2;

            //Coin supérieur gauche-ROI pour la construction d'un quadrant
            Mat q0 = new Mat(mag, new Rect(0, 0, cx, cy));
            //Coin supérieur droit
            Mat q1 = new Mat(mag, new Rect(cx, 0, cx, cy));
            //Coin inférieur gauche
            Mat q2 = new Mat(mag, new Rect(0, cy, cx, cy));
            //Le coin inférieur droit
            Mat q3 = new Mat(mag, new Rect(cx, cy, cx, cy));

            Mat tmp = new Mat();
            q0.copyTo(tmp);
            q3.copyTo(q0);
            //Quadrant d'échange:En haut à gauche 與 en bas à droite
            tmp.copyTo(q3);

            q1.copyTo(tmp);
            q2.copyTo(q1);
            //Quadrant d'échange:En haut à droite, en bas à gauche
            tmp.copyTo(q2);
            //end part3 shiftDFT

            // normalize the magnitude image for the visualization since both JavaFX
            // and OpenCV need images with value between 0 and 255
            //Normalisation[0,255]intervalle
            Core.normalize(mag, mag, 0,255, Core.NORM_MINMAX);
            //end part2 createOptimizedMagnitude


            //Imgproc.GaussianBlur(source1, processBlur,new Size(GaussianKernelSize,GaussianKernelSize),0,0);
            //Mat lastoutput = ConvertDFTToImage(Dft,gaussianFilter,output);
            //source.convertTo(destination, -1, alpha, beta);
            Imgcodecs.imwrite("D:\\projects\\Java\\OpenCV_Samples\\resource\\imgs\\lena-dft.jpg ", mag);
            //main end
        }catch (Exception e) {
            System.out.println("error: " + e.getMessage());
        }
    }
}

Result
![lena.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/276243/697b070e-ff11-4ec5-490a-b30913b26a69.jpeg)

lena-dft.jpg

Recommended Posts

Bureau: OpenCV Dft
Bureau: seuil OpenCV
Bureau: OpenCV BilateralFilterBlur
Bureau: OpenCV Dilate
Bureau: OpenCV Expand
Bureau: OpenCV Affine
Bureau: OpenCV Emboss
Bureau: OpenCV Ellipse2Poly
Bureau: OpenCV HDR
Bureau: Polylignes OpenCV
Bureau: netteté OpenCV
Bureau: OpenCV Concat
Bureau: OpenCV OpenCV_SalonUseBlurAddWeighted
Bureau: OpenCV Mosaic
Bureau: OpenCV Erode
Bureau: OpenCV Denoise
Bureau: Rectangle OpenCV
Bureau: OpenCV Watershed
Bureau: Texte OpenCV
Bureau: OpenCV Inpaint
Bureau: OpenCV NormalizeBlur
Bureau: OpenCV Canny
Bureau: OpenCV Denoise3
Bureau: histogramme OpenCV
Bureau: OpenCV Decolor
Bureau: OpenCV FaceDetector
Bureau: OpenCV Denoise2
Bureau: OpenCV StereoBM
Bureau: Filtre OpenCV Kirsch
Bureau: Filtre laplacien OpenCV 2
Bureau: Changement d'éclairage OpenCV
Bureau: OpenCV Add WaterMark
Bureau: OpenCV Fill ConvexPoly
Bureau: OpenCV Grab Cut
Bureau: OpenCV Sharpness Gui
Bureau: Changement de couleur OpenCV
Bureau: Filtre Freichennel OpenCV
Bureau: seuil adaptatif OpenCV
Bureau: OpenCV Fill Poly
Bureau: OpenCV Mean Filter
Bureau: référentiel Java OpenCV
Bureau: OpenCV Sobel Filter2
Bureau: OpenCV pyrMeanShift Filter
Bureau: OpenCV OpticalFlow PyrLK
Bureau: Piano virtuel OpenCV
Bureau: image de fusion OpenCV
Bureau: Filtre OpenCV Scharr
Bureau: aperçu de la webcam Opencv
Bureau: Filtre laplacien OpenCV
Bureau: Flou médian OpenCV
Bureau: OpenCV Add Broad
Bureau: enregistrement vidéo OpenCV
Bureau: OpenCV Flood Fill
Bureau: espace colorimétrique OpenCV
Bureau: Filtre OpenCV SqrBox
Bureau: redimensionner l'image OpenCV
Bureau: Croquis au crayon OpenCV
Bureau: carte des couleurs OpenCV
Bureau: OpenCV Seamless Clone
Bureau: OpenCV Draw Point
Bureau: OpenCV Sobel Filter