当前位置:首页 > 代码 > 正文

基于边缘匹配图形代码(边缘匹配概念)

admin 发布:2022-12-19 05:52 135


今天给各位分享基于边缘匹配图形代码的知识,其中也会对边缘匹配概念进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

本文目录一览:

matlab图像分块,边缘检测,图像拼接代码

你可以试试下面的程序:

I=imread('myphoto.jpg'); % 假设要处理的图像是myphoto.jpg

heights=size(I,1); % 图像的高

widths=size(I,2); % 图像的宽

m=8; % 假设纵向分成8幅图

n=10; % 假设横向分成10幅图

% 考虑到rows和cols不一定能被m和n整除,所以对行数和列数均分后要取整

rows=round(linspace(0,heights,m+1)); % 各子图像的起始和终止行标

cols=round(linspace(0,widths,n+1)); % 各子图像的起始和终止列标

blocks=cell(m,n); % 用一个单元数组容纳各个子图像

for k1=1:m

for k2=1:n

blocks{k1,k2}=I(rows(k1)+1:rows(k1+1),cols(k2)+1:cols(k2+1),:);

subimage=blocks{k1,k2};

% 以下是对subimage进行边缘检测

% 加入边缘检测的代码

% 以上是对subimage进行边缘检测

blocks{k1,k2}=subimage;

end

end

processed=I; % processed为处理后的图像,用原图像对其初始化

% 以下为拼接图像

for k1=1:m

for k2=1:n

processed(rows(k1)+1:rows(k1+1),cols(k2)+1:cols(k2+1),:)=blocks{k1,k2};

end

end

figure,imshow(processed)

% 以上的程序已测试过,对灰度图像和真彩图像都可以运行。

如何利用OPENCV的matchShapes进行轮廓匹配?

主要步骤1.读取一幅图片,并且对其进行二值化。2.对其进行形态学处理,减少孔洞等次要特征,保留其主要特征。3.进行边缘提取。4.进行形状轮廓匹配,得到其匹配值,从而判断是否是同一个形状。

下面是演示代码:

#include

#include"opencv2/opencv.hpp"

usingnamespacestd;

usingnamespacecv;

intmain()

{

Matk=imread("E:/TestGit/8.jpg",0);

Matf;

Matk1=imread("E:/TestGit/9.jpg",0);

Matf1;

threshold(k,f,50,255,THRESH_BINARY);//对图像进行二值化

threshold(k1,f1,50,255,THRESH_BINARY);

Matcloserect=getStructuringElement(MORPH_RECT,Size(3,3));//进行结构算子生成

morphologyEx(f,f,MORPH_OPEN,closerect);

morphologyEx(f1,f1,MORPH_OPEN,closerect);//进行形态学开运算

Matdst=Mat::zeros(k.rows,k.cols,CV_8UC3);

Matdst1=Mat::zeros(k1.rows,k1.cols,CV_8UC3);

vectorw,w1;

vectorhierarchy,hierarchy1;

findContours(f,w,hierarchy,RETR_CCOMP,CHAIN_APPROX_SIMPLE);//提取轮廓元素

findContours(f1,w1,hierarchy1,RETR_CCOMP,CHAIN_APPROX_SIMPLE);

FileStoragefs("f.dat",FileStorage::WRITE);

fs

intidx=0;

doubleffff=matchShapes(w[0],w1[0],CV_CONTOURS_MATCH_I3,1.0);//进行轮廓匹配

std::cout

system("pause");

return0;

}

这样,我们就得到了轮廓边缘的提取和匹配,满足了需要。而不同的算子具有不同的匹配算子方法。

如何利用OPENCV的matchShapes进行轮廓匹配

0),w1,THRESH_BINARY),CV_CONTOURS_MATCH_I3, CV_8UC3),w1;/, k;

Mat f;E主要步骤1,closerect);;/w1[0]; w;,减少孔洞等次要特征,255;

Mat closerect=getStructuringElement(MORPH_RECT;/.读取一幅图片;pause",3))。而不同的算子具有不同的匹配算子方法::WRITE).jpg",50,RETR_CCOMP,w,满足了需要:.进行形状轮廓匹配;

int idx=0,并且对其进行二值化;

system("f",0),我们就得到了轮廓边缘的提取和匹配:zeros(k1:,hierarchy1 ,CHAIN_APPROX_SIMPLE), CV_8UC3), k1;opencv;

using namespace cv:,255.dat",f;std;进行结构算子生成

morphologyEx(f:zeros(k;iostream/

findContours(f.对其进行形态学处理。4;8;

double ffff=matchShapes(w[0];

vector对图像进行二值化

threshold(k1,CHAIN_APPROX_SIMPLE),保留其主要特征,RETR_CCOMP;

Mat dst1 = Mat;ffffTestGit/TestGit/.进行边缘提取;E;提取轮廓元素

findContours(f1;/。3;/f,Size(3.rows,FileStorage;

morphologyEx(f1;/Point进行形态学开运算

Mat dst = Mat,w1[0];

Mat k1=imread(":cout.rows:

#include

Mat f1;

int main()

{

Mat k=imread(".jpg":;/进行轮廓匹配

std,得到其匹配值,hierarchy1,从而判断是否是同一个形状; /

using namespace std,f1,MORPH_OPEN;/,THRESH_BINARY),closerect),hierarchy。

下面是演示代码,MORPH_OPEN。2;

#include " hierarchy;

vector.cols:endl;:/,1;opencv2/Vec4i

return 0;

fs".hpp"

FileStorage fs(",50:/.cols;9;

threshold(k;;

}

这样,0),f1;vector,f;);;

哪位大哥给个 图像边缘检测 C++程序代码

将常用的检测实现公式列出如下:

Roberts算子:G[i,i]=|f[i,j]-f[i+1,j+1]|+|f[i+1,j]-f[i,j+1]|;

Sobe算子:G[i,i]=|f[i-1,j+1]+2f[i,j+1]+f[i+1,j+1]-f[i-1,j-1]-2f[i,j-1]-f[i+1,j-1]|

+|f[i-1,j-1]+2f[i-1,j]+f[i-1,j+1]-f[i+1,j-1]-2f[i+1,j]-f[i+1,j+1]|;

拉普拉斯算子:G[I,j]=|f[i+1,j]+f[i-1,j]+f(i,j+1)+f[i,j-1]-4f[i,j]|;

其中G[i,j]表示处理后(i,j)点的灰度值,f[i,j]表示处理前该点的灰度值。

不过用robert算法实现的没有找到具体的源代码,下面有一个Sobe算子实现的:

在视图类中定义的响应菜单命令的边缘检测Sobel算子实现灰度图像边缘检测的函数:

void CDibView::OnMENUSobel()

//灰度图像数据的获得参见天极网9.10日发表的拙作//VC数字图像处理一文

{

HANDLE data1handle;

LPBITMAPINFOHEADER lpBi;

CDibDoc *pDoc=GetDocument();

HDIB hdib;

unsigned char *hData;

unsigned char *data;

hdib=pDoc-m_hDIB;

BeginWaitCursor();

lpBi=(LPBITMAPINFOHEADER)GlobalLock((HGLOBAL)hdib);

hData= lpbi +* (LPDWORD)lpbi + 256*sizeof(RGBQUAD);

//得到指向位图像素值的指针

pDoc-SetModifiedFlag(TRUE);//设修改标志为"TRUE"

data1handle=GlobalAlloc(GMEM_SHARE,WIDTHBYTES(lpBi-biWidth*8)*lpBi-biHeight);

//申请存放处理后的像素值的缓冲区

data=(unsigned char*)GlobalLock((HGLOBAL)data1handle);

AfxGetApp()-BeginWaitCursor();

int i,j,buf,buf1,buf2;

for( j=0; jbiHeight; j++)//以下循环求(x,y)位置的灰度值

for( i=0; ibiWidth; i++)

{

if(((i-1)=0)((i+1)biWidth)((j-1)=0)((j+1)biHeight))

{//对于图像四周边界处的向素点不处理

buf1=(int)*(hData+(i+1)*WIDTHBYTES(lpBi-biWidth*8)+(j-1))

+2*(int)*(hData+(i+1)*WIDTHBYTES(lpBi-biWidth*8)+(j))

+(int)(int)*(hData+(i+1)*WIDTHBYTES(lpBi-biWidth*8)+(j+1));

buf1=buf1-(int)(int)*(hData+(i-1)*WIDTHBYTES(lpBi-biWidth*8)+(j-1))

-2*(int)(int)*(hData+(i-1)*WIDTHBYTES(lpBi-biWidth*8)+(j))

-(int)(int)*(hData+(i-1)*WIDTHBYTES(lpBi-biWidth*8)+(j+1));

//x方向加权微分

buf2=(int)(int)*(hData+(i-1)*WIDTHBYTES(lpBi-biWidth*8)+(j+1))

+2*(int)(int)*(hData+(i)*WIDTHBYTES(lpBi-biWidth*8)+(j+1))

+(int)(int)*(hData+(i+1)*WIDTHBYTES(lpBi-biWidth*8)+(j+1));

buf2=buf2-(int)(int)*(hData+(i-1)*WIDTHBYTES(lpBi-biWidth*8)+(j-1))

-2*(int)(int)*(hData+(i)*WIDTHBYTES(lpBi-biWidth*8)+(j-1))

-(int)(int)*(hData+(i+1)*WIDTHBYTES(lpBi-biWidth*8)+(j-1));

//y方向加权微分

buf=abs(buf1)+abs(buf2);//求梯度

if(buf255) buf=255;

if(buf0)

else *(data+i*lpBi-biWidth+j)=(BYTE)0;

}

for( j=0; jbiHeight; j++)

for( i=0; ibiWidth; i++)

*(hData+i*WIDTHBYTES(lpBi-biWidth*8)+j)=*(data+i*WIDTHBYTES(lpBi-biWidth*8)+j);

//处理后的数据写回原缓冲区

AfxGetApp()-EndWaitCursor();

GlobalUnlock((HGLOBAL)hdib);

GlobalUnlock(data1handle);

GlobalFree(date1handle);

EndWaitCursor();

Invalidate(TRUE);

}

具体的分析给你一个链接吧:

对图像进行边缘特征提取程序代码

基于小波变换的多尺度图像边缘检测matlab源代码(在Matlab7.0下运行)

clear all;

load wbarb;

I = ind2gray(X,map);imshow(I);

I1 = imadjust(I,stretchlim(I),[0,1]);figure;imshow(I1);

[N,M] = size(I);

h = [0.125,0.375,0.375,0.125];

g = [0.5,-0.5];

delta = [1,0,0];

J = 3;

a(1:N,1:M,1,1:J+1) = 0;

dx(1:N,1:M,1,1:J+1) = 0;

dy(1:N,1:M,1,1:J+1) = 0;

d(1:N,1:M,1,1:J+1) = 0;

a(:,:,1,1) = conv2(h,h,I,'same');

dx(:,:,1,1) = conv2(delta,g,I,'same');

dy(:,:,1,1) = conv2(g,delta,I,'same');

x = dx(:,:,1,1);

y = dy(:,:,1,1);

d(:,:,1,1) = sqrt(x.^2+y.^2);

I1 = imadjust(d(:,:,1,1),stretchlim(d(:,:,1,1)),[0 1]);figure;imshow(I1);

lh = length(h);

lg = length(g);

for j = 1:J+1

lhj = 2^j*(lh-1)+1;

lgj = 2^j*(lg-1)+1;

hj(1:lhj)=0;

gj(1:lgj)=0;

for n = 1:lh

hj(2^j*(n-1)+1)=h(n);

end

for n = 1:lg

gj(2^j*(n-1)+1)=g(n);

end

a(:,:,1,j+1) = conv2(hj,hj,a(:,:,1,j),'same');

dx(:,:,1,j+1) = conv2(delta,gj,a(:,:,1,j),'same');

dy(:,:,1,j+1) = conv2(gj,delta,a(:,:,1,j),'same');

x = dx(:,:,1,j+1);

y = dy(:,:,1,j+1);

dj(:,:,1,j+1) = sqrt(x.^2+y.^2);

I1 = imadjust(dj(:,:,1,j+1),stretchlim(dj(:,:,1,j+1)),[0 1]);figure;imshow(I1);

End

求基于sift特征提取的图像匹配代码,最好是利用C++和opencv编写

哈哈,我有一个基于opencv实现的sift,我把代码贴出来,你自己看看吧~~~

void sift_detector_and_descriptors(IplImage* i_left,IplImage* i_right)

{

Mat mat_image_left=Mat(i_left,false);

Mat mat_image_right=Mat(i_right,false);

cv::SiftFeatureDetector *pDetector=new cv::SiftFeatureDetector;

pDetector-detect(mat_image_left,left_key_point);

pDetector-detect(mat_image_right,right_key_point);

Mat left_image_descriptors,right_image_descriptors;

cv::SiftDescriptorExtractor *descriptor_extractor=new cv::SiftDescriptorExtractor;

descriptor_extractor-compute(mat_image_left,left_key_point,left_image_descriptors);

descriptor_extractor-compute(mat_image_right,right_key_point,right_image_descriptors);

Mat result_l,result_r;

drawKeypoints(mat_image_left,left_key_point,result_l,Scalar::all(-1),0);

drawKeypoints(mat_image_right,right_key_point,result_r,Scalar::all(-1),0);

//imshow("result_of_left_detector_sift",result_l);

//imshow("result_of_right_detector_sift",result_r);

Mat result_of_sift_match;

BruteForceMatcherL2float matcher;

matcher.match(left_image_descriptors,right_image_descriptors,result_of_point_match);

drawMatches(mat_image_left,left_key_point,mat_image_right,right_key_point,result_of_sift_match,result_of_sift_match);

imshow("matches_of_sift",result_of_sift_match);

imwrite("matches_of_sift.jpg",result_of_sift_match);

}

void main()

{

IplImage *n_left_image=cvLoadImage("D:\\lena.jpg");

IplImage *n_right_image=cvLoadImage("D:\\lena_r.jpg");

sift_detector_and_descriptors(n_left_image,n_right_image);

cvWaitKey(0);

}

这就是核心代码了,至于opencv所要用到的库,你自己弄一下吧,每个人的opencv版本不一样,这个都市不同的,希望能够帮到你~

关于基于边缘匹配图形代码和边缘匹配概念的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。

版权说明:如非注明,本站文章均为 AH站长 原创,转载请注明出处和附带本文链接;

本文地址:http://ahzz.com.cn/post/3395.html


取消回复欢迎 发表评论:

分享到

温馨提示

下载成功了么?或者链接失效了?

联系我们反馈

立即下载