×

分水岭算法 帮帮

帮帮我 我不知道分水岭算法在图像分割中的应用 代码,还有别的帮帮我?opencv 分水岭分割算法的问题,算出的marker是用-1来表示分割线是什么意思,下面两种convertTo能解释下吗

admin admin 发表于2024-02-10 07:38:28 浏览35 评论0

抢沙发发表评论

本篇文章给大家谈谈分水岭算法,以及帮帮我 我不知道分水岭算法在图像分割中的应用 代码,还有别的帮帮我对应的知识点,文章可能有点长,但是希望大家可以阅读完,增长自己的知识,最重要的是希望对各位有所帮助,可以解决了您的问题,不要忘了收藏本站喔。

本文目录

帮帮我 我不知道分水岭算法在图像分割中的应用 代码,还有别的帮帮我

clear,clc%三种方法进行分水岭分割%读入图像filename=’sar1.bmp’;f=imread(filename);Info=imfinfo(filename);if Info.BitDepth》8 f=rgb2gray(f);endfigure,mesh(double(f));%显示图像,类似集水盆地%方法1:一般分水岭分割,从结果可以看出存在过分割问题b=im2bw(f,graythresh(f));%二值化,注意应保证集水盆地的值较低(为0),否则就要对b取反d=bwdist(b); %求零值到最近非零值的距离,即集水盆地到分水岭的距离 l=watershed(-d); %matlab自带分水岭算法,l中的零值即为风水岭w=l==0; %取出边缘g=b&~w; %用w作为mask从二值图像中取值figuresubplot(2,3,1),imshow(f);subplot(2,3,2),imshow(b);subplot(2,3,3),imshow(d);subplot(2,3,4),imshow(l);subplot(2,3,5),imshow(w);subplot(2,3,6),imshow(g);%方法2:使用梯度的两次分水岭分割,从结果可以看出还存在过分割问题(在方法1的基础上改进)h=fspecial(’sobel’);%获得纵方向的sobel算子fd=double(f);g=sqrt(imfilter(fd,h,’replicate’).^2+imfilter(fd,h’,’replicate’).^2);%使用sobel算子进行梯度运算l=watershed(g);%分水岭运算wr=l==0; g2=imclose(imopen(g,ones(3,3)),ones(3,3));%进行开闭运算对图像进行平滑l2=watershed(g2);%再次进行分水岭运算wr2=l2==0;f2=f;f2(wr2)=255;figuresubplot(2,3,1),imshow(f);subplot(2,3,2),imshow(g);subplot(2,3,3),imshow(l);subplot(2,3,4),imshow(g2);subplot(2,3,5),imshow(l2);subplot(2,3,6),imshow(f2);%方法3:使用梯度加掩模的三次分水岭算法(在方法2的基础上改进)h=fspecial(’sobel’);%获得纵方向的sobel算子fd=double(f);g=sqrt(imfilter(fd,h,’replicate’).^2+imfilter(fd,h’,’replicate’).^2);%使用sobel算子进行梯度运算l=watershed(g);%分水岭运算wr=l==0; rm=imregionalmin(g); %计算图像的区域最小值定位,该函数仅仅是用来观察为何分水岭算法产生这么多集水盆地im=imextendedmin(f,2);%上面仅是产生最小值点,而该函数则是得到最小值附近的区域,此处的附近是相差2的区域fim=f; fim(im)=175; %将im在原图上标识出,用以观察 lim=watershed(bwdist(im));%再次分水岭计算em=lim==0;g2=imimposemin(g,im|em);%在梯度图上标出im和em,im是集水盆地的中心,em是分水岭l2=watershed(g2); %第三次分水岭计算f2=f;f2(l2==0)=255; %从原图对分水岭进行观察figuresubplot(3,3,1),imshow(f);subplot(3,3,2),imshow(g);subplot(3,3,3),imshow(l);subplot(3,3,4),imshow(im);subplot(3,3,5),imshow(fim);subplot(3,3,6),imshow(lim);subplot(3,3,7),imshow(g2);subplot(3,3,8),imshow(l2)subplot(3,3,9),imshow(f2);

opencv 分水岭分割算法的问题,算出的marker是用-1来表示分割线是什么意思,下面两种convertTo能解释下吗

整个项目的结构图:编写DetectFaceDemo.java,代码如下: view plaincopyprint?package com.njupt.zhb.test; import org.opencv.core.Core; import org.opencv.core.Mat; import org.opencv.core.MatOfRect; import org.opencv.core.Point; import org.opencv.core.Rect; import org.opencv.core.Scalar; import org.opencv.highgui.Highgui; import org.opencv.objdetect.CascadeClassifier; // // Detects faces in an image, draws boxes around them, and writes the results // to "faceDetection.png". // public class DetectFaceDemo { public void run() { System.out.println("\nRunning DetectFaceDemo"); System.out.println(getClass().getResource("lbpcascade_frontalface.xml").getPath()); // Create a face detector from the cascade file in the resources // directory. //CascadeClassifier faceDetector = new CascadeClassifier(getClass().getResource("lbpcascade_frontalface.xml").getPath()); //Mat image = Highgui.imread(getClass().getResource("lena.png").getPath()); //注意:源程序的路径会多打印一个‘/’,因此总是出现如下错误 /* * Detected 0 faces Writing faceDetection.png libpng warning: Image * width is zero in IHDR libpng warning: Image height is zero in IHDR * libpng error: Invalid IHDR data */ //因此,我们将第一个字符去掉 String xmlfilePath=getClass().getResource("lbpcascade_frontalface.xml").getPath().substring(1); CascadeClassifier faceDetector = new CascadeClassifier(xmlfilePath); Mat image = Highgui.imread(getClass().getResource("we.jpg").getPath().substring(1)); // Detect faces in the image. // MatOfRect is a special container class for Rect. MatOfRect faceDetections = new MatOfRect(); faceDetector.detectMultiScale(image, faceDetections); System.out.println(String.format("Detected %s faces", faceDetections.toArray().length)); // Draw a bounding box around each face. for (Rect rect : faceDetections.toArray()) { Core.rectangle(image, new Point(rect.x, rect.y), new Point(rect.x + rect.width, rect.y + rect.height), new Scalar(0, 255, 0)); } // Save the visualized detection. String filename = "faceDetection.png"; System.out.println(String.format("Writing %s", filename)); Highgui.imwrite(filename, image); } } package com.njupt.zhb.test;import org.opencv.core.Core;import org.opencv.core.Mat;import org.opencv.core.MatOfRect;import org.opencv.core.Point;import org.opencv.core.Rect;import org.opencv.core.Scalar;import org.opencv.highgui.Highgui;import org.opencv.objdetect.CascadeClassifier;//// Detects faces in an image, draws boxes around them, and writes the results// to "faceDetection.png".//public class DetectFaceDemo { public void run() { System.out.println("\nRunning DetectFaceDemo"); System.out.println(getClass().getResource("lbpcascade_frontalface.xml").getPath()); // Create a face detector from the cascade file in the resources // directory. //CascadeClassifier faceDetector = new CascadeClassifier(getClass().getResource("lbpcascade_frontalface.xml").getPath()); //Mat image = Highgui.imread(getClass().getResource("lena.png").getPath()); //注意:源程序的路径会多打印一个‘/’,因此总是出现如下错误/** Detected 0 faces Writing faceDetection.png libpng warning: Image* width is zero in IHDR libpng warning: Image height is zero in IHDR* libpng error: Invalid IHDR data*/ //因此,我们将第一个字符去掉 String xmlfilePath=getClass().getResource("lbpcascade_frontalface.xml").getPath().substring(1); CascadeClassifier faceDetector = new CascadeClassifier(xmlfilePath); Mat image = Highgui.imread(getClass().getResource("we.jpg").getPath().substring(1)); // Detect faces in the image. // MatOfRect is a special container class for Rect. MatOfRect faceDetections = new MatOfRect(); faceDetector.detectMultiScale(image, faceDetections); System.out.println(String.format("Detected %s faces", faceDetections.toArray().length)); // Draw a bounding box around each face. for (Rect rect : faceDetections.toArray()) { Core.rectangle(image, new Point(rect.x, rect.y), new Point(rect.x + rect.width, rect.y + rect.height), new Scalar(0, 255, 0)); } // Save the visualized detection. String filename = "faceDetection.png"; System.out.println(String.format("Writing %s", filename)); Highgui.imwrite(filename, image); }}3.编写测试类: view plaincopyprint?package com.njupt.zhb.test; public class TestMain { public static void main(String args) { System.out.println("Hello, OpenCV"); // Load the native library. System.loadLibrary("opencv_java246"); new DetectFaceDemo().run(); } } //运行结果: //Hello, OpenCV // //Running DetectFaceDemo ///E:/eclipse_Jee/workspace/JavaOpenCV246/bin/com/njupt/zhb/test/lbpcascade_frontalface.xml //Detected 8 faces //Writing faceDetection.png package com.njupt.zhb.test;public class TestMain { public static void main(String args) { System.out.println("Hello, OpenCV"); // Load the native library. System.loadLibrary("opencv_java246"); new DetectFaceDemo().run(); }}//运行结果://Hello, OpenCV////Running DetectFaceDemo///E:/eclipse_Jee/workspace/JavaOpenCV246/bin/com/njupt/zhb/test/lbpcascade_frontalface.xml//Detected 8 faces//Writing faceDetection.png

文章分享结束,分水岭算法和帮帮我 我不知道分水岭算法在图像分割中的应用 代码,还有别的帮帮我的答案你都知道了吗?欢迎再次光临本站哦!