List of usage examples for org.opencv.core Mat Mat
public Mat(Mat m, Range rowRange, Range colRange)
From source file:cpsd.ImageGUI.java
private void AnalyzeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_AnalyzeButtonActionPerformed try {/*w ww . j av a 2 s . c o m*/ double pixelArea = 1; double imageSize = 1; if (magnification == 50) pixelArea = 1.2996; else if (magnification == 100) pixelArea = 0.329476; else if (magnification == 200) pixelArea = 0.08162; else { imageSize = pow(10, 10) * pow(magnification, -2); pixelArea = (imageSize) / (resolution1 * resolution2); } Mat source = ImageClass.getInstance().getImage(); Mat destination = new Mat(source.rows(), source.cols(), source.type()); //Imgproc.adaptiveThreshold(source,destination,255,ADAPTIVE_THRESH_GAUSSIAN_C,THRESH_BINARY_INV,13,2); //Imgproc.GaussianBlur(destination,destination,new org.opencv.core.Size(0,0),5); threshold(source, destination, 30, 255, CV_THRESH_BINARY); distanceTransform(destination, destination, CV_DIST_L2, 3); normalize(destination, destination, 0, 1, NORM_MINMAX); threshold(destination, destination, 0.5, 1, CV_THRESH_BINARY); destination.convertTo(destination, CV_8U); /*ImageClass.getInstance().setImage(destination); displayImage();*/ ArrayList<MatOfPoint> contours = new ArrayList<MatOfPoint>(); MatOfInt4 hierarchy = new MatOfInt4(); // Rect roi = new Rect(100,100,destination.cols()-100,destination.rows()-100); // Mat imageROI = destination.submat(roi); /*ImageClass.getInstance().setImage(imageROI); displayImage();*/ //Imgproc.Canny(source,destination,0.05,0.15); Imgproc.findContours(destination, contours, hierarchy, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE); int total = contours.size(); int count = 0; //System.out.println(total); MatOfPoint[] cntrs = contours.toArray(new MatOfPoint[contours.size()]); ArrayList<Double> value = new ArrayList<Double>(); double temp = 0; for (int i = 0; i < contours.size(); i++) { if (contourArea(cntrs[i]) > 1/*&& contourArea(cntrs[i])<3000*/) { temp = 2 * Math.sqrt((contourArea(cntrs[i]) * (pixelArea)) / Math.PI); //temp = contourArea(cntrs[i]); if (temp > 0) { value.add(count, temp); System.out.println("area of contour " + count++ + " is : " + contourArea(cntrs[i])); } } } System.out.println("total number of contours : " + count); double[] values = new double[count]; for (int i = 0; i < count; i++) { //temp = value.get(i);//2*Math.sqrt((value.get(i)*127.024)/Math.PI); //if(temp>0) values[i] = value.get(i); //System.out.println("the diameter of particle "+i+ "is "+values[i]); // values[i]=(contourArea(cntrs[i])*127.024)/100; } //int number = 300; /*HistogramDataset dataset = new HistogramDataset(); dataset.setType(HistogramType.FREQUENCY); XYSeries series = new XYSeries("Particle Size Distribution"); try{ dataset.addSeries("Histogram1",values,number,0,300); for(int i=0;i<300;i++){ if(dataset.getYValue(0,i)>0) series.add(dataset.getXValue(0,i),dataset.getYValue(0,i)); } // XYDataset xydataset = new XYSeriesCollection(series); }catch(Exception e) { e.printStackTrace(); } XYDataset xydataset = new XYSeriesCollection(series); String plotTitle = "Particle Size Distribution"; String xAxis = "particle diameter in microns"; String yAxis = "particle count"; PlotOrientation orientation = PlotOrientation.VERTICAL; boolean show = true; boolean toolTips = true; boolean urls = false; JFreeChart chart1 = ChartFactory.createXYLineChart(plotTitle,xAxis,yAxis,xydataset,orientation,show,toolTips,urls); JFreeChart chart2 = ChartFactory.createHistogram(plotTitle,xAxis,yAxis,dataset,orientation,show,toolTips,urls); int width1 = 500; int height1 = 500; ChartFrame frame1 = new ChartFrame("Coal PSD",chart1); frame1.setSize(width1,height1); frame1.setVisible(true); frame1.setDefaultCloseOperation(DISPOSE_ON_CLOSE); int width2 = 500; int height2 = 500; ChartFrame frame2 = new ChartFrame("Coal PSD",chart2); frame2.setSize(width2,height2); frame2.setVisible(true); frame2.setDefaultCloseOperation(DISPOSE_ON_CLOSE);*/ } catch (NullPointerException e) { System.err.println("..........Please load a valid Image.........."); } // TODO add your handling code here: }
From source file:cpsd.ImageGUI.java
private void rgb2Gray() { //String str = path.getText().toString(); Mat source = ImageClass.getInstance().getImage(); Mat destination = new Mat(source.rows(), source.cols(), CV_8UC1); Imgproc.cvtColor(source, destination, COLOR_RGB2GRAY); ImageClass.getInstance().setImage(destination); }
From source file:cpsd.ImageGUI.java
private void zoomImage(double zoomlevel) { Mat source = ImageClass.getInstance().getImage(); Mat destination = new Mat((int) (source.rows() * zoomlevel), (int) (source.cols() * zoomlevel), source.type());// w ww. ja v a 2 s . c om Imgproc.resize(source, destination, destination.size(), zoomlevel, zoomlevel, INTER_CUBIC); ImageClass.getInstance().setImage(destination); zoomSlider.setValue((int) (zoomlevel * 10)); }
From source file:cpsd.ImageGUI.java
private void enhanceContrast() { System.loadLibrary(Core.NATIVE_LIBRARY_NAME); //System.load("/usr/local/share/OpenCV/java/libopencv_java249.so"); // rgb2Gray(); Mat source = ImageClass.getInstance().getImage(); Mat destination = new Mat(source.rows(), source.cols(), source.type()); Imgproc.equalizeHist(source, destination); image.getInstance().setImage(destination); }
From source file:cpsd.ImageGUI.java
private void enhanceSharpness(double alpha) { System.loadLibrary(Core.NATIVE_LIBRARY_NAME); // System.load("/usr/local/share/OpenCV/java/libopencv_java249.so"); Mat source = ImageClass.getInstance().getImage(); Mat destination = new Mat(source.rows(), source.cols(), source.type()); /// GaussianBlur(Mat src, Mat dst, Size ksize, double sigmaX); Imgproc.GaussianBlur(source, destination, new org.opencv.core.Size(0, 0), 10); ///addWeighted(Mat src1, double alpha, Mat src2, double beta, double gamma, Mat dst); Core.addWeighted(source, alpha, destination, -0.5, 0, destination); ImageClass.getInstance().setImage(destination); sharpSlider.setValue((int) (alpha * 10)); }
From source file:cpsd.ImageGUI.java
private void enhanceBrightness(double alpha) { Mat source = ImageClass.getInstance().getImage(); Mat destination = new Mat(source.rows(), source.cols(), source.type()); source.convertTo(destination, -1, alpha, 50); ImageClass.getInstance().setImage(destination); // brightSlider.setValue((int)(alpha*10)); }
From source file:cpsd.ImageGUI.java
private void transform(final int[][] arr) { try {/*from w w w. j a v a 2 s . c o m*/ int kernelSize = 3; System.loadLibrary(Core.NATIVE_LIBRARY_NAME); //System.load("/usr/local/share/OpenCV/java/libopencv_java249.so"); // System.loadLibrary( Core.NATIVE_LIBRARY_NAME ); Mat source = ImageClass.getInstance().getImage(); Mat destination = new Mat(source.rows(), source.cols(), source.type()); Mat kernel = new Mat(kernelSize, kernelSize, CvType.CV_32F) { { for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { System.out.println(arr[i][j]); put(i, j, arr[i][j]); } } } }; Imgproc.filter2D(source, destination, -1, kernel); ImageClass.getInstance().setImage(destination); } catch (Exception e) { System.out.println("Error: " + e.getMessage()); } }
From source file:ctPrincipal.Filtros.java
private void IniciaFiltros() { this.output = new Mat(256, 26, CvType.CV_8UC3); LoadImagA(); }
From source file:ctPrincipal.Filtros.java
private void LoadImagA() { try {// w ww . ja v a2 s. co m BufferedImage imageA = ImageIO.read(imgF); byte[] data = ((DataBufferByte) imageA.getRaster().getDataBuffer()).getData(); image = new Mat(imageA.getHeight(), imageA.getWidth(), CvType.CV_8UC3); image.put(0, 0, data); } catch (IOException ex) { Logger.getLogger(Operacoes.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:ctPrincipal.Graficos.java
public Graficos(String[] listImg) { this.arquivos = listImg; this.ruido = new Mat(256, 256, CvType.CV_8UC3); }