显著性区域检测matlab-code-20170412_第1页
显著性区域检测matlab-code-20170412_第2页
显著性区域检测matlab-code-20170412_第3页
显著性区域检测matlab-code-20170412_第4页
显著性区域检测matlab-code-20170412_第5页
已阅读5页,还剩3页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

Main_program%====test1clearcloseallclc%加8_皿,输入的待处理的图像%n,图像分块的patch的大小%img_rgb:缩放后的rgb图%img_lab:rgb2lab后的图%h,w,图像高宽%mex_store,存储矩阵img=imread('test1.jpg');%img=imread('E:^^^matlab\显著性分割\假设已知均值\testpicture\0010.tif);max_side=120;yu_value=0.8;img_lab=pre_rgb2lab(img,max_side);[img_scale_1,img_scale_2,img_scale_3,img_scale_4]=get4Scale(img_lab);[DistanceValue_scale_1_t1,DistanceValue_scale_1_exp,DistanceValue_scale_1_t1_rang,DistanceValue_scale_1_exp_rang]=distanceValueMap_search_onescale_2(img_scale_1,max_side);[DistanceValue_scale_2_t1,DistanceValue_scale_2_exp,DistanceValue_scale_2_t1_rang,DistanceValue_scale_2_exp_rang]=distanceValueMap_search_onescale_2(img_scale_2,max_side);[DistanceValue_scale_3_t1,DistanceValue_scale_3_exp,DistanceValue_scale_3_t1_rang,DistanceValue_scale_3_exp_rang]=distanceValueMap_search_onescale_2(img_scale_3,max_side);[DistanceValue_scale_4_t1,DistanceValue_scale_4_exp,DistanceValue_scale_4_t1_rang,DistanceValue_scale_4_exp_rang]=distanceValueMap_search_onescale_2(img_scale_4,max_side);value_C_1=Center_weight(DistanceValue_scale_1_exp_rang,yu_value);value_C_2=Center_weight(DistanceValue_scale_2_exp_rang,yu_value);value_C_3=Center_weight(DistanceValue_scale_3_exp_rang,yu_value);value_C_4=Center_weight(DistanceValue_scale_4_exp_rang,yu_value);[h,w]=size(value_C_1);value_C_1_resize=value_C_1;value_C_2_resize=imresize(value_C_2,[h,w]);value_C_3_resize=imresize(value_C_3,[h,w]);value_C_4_resize=imresize(value_C_4,[h,w]);value_C_sum=(value_C_1_resize+value_C_2_resize+value_C_3_resize+value_C_4_resize)/4;figure,imshow(value_C_sum);figure,imshow(value_C_1_resize);figure,imshow(value_C_2_resize);figure,imshow(value_C_3_resize);figure,imshow(value_C_4_resize);8888888888888888888888888888888888888888888888888888888888888888888888888888Center_weightfunction[img_out]=Center_weight(img_in,yu_value)%UNTITLEDSummaryofthisfunctiongoeshere%Detailedexplanationgoeshereimg_in=mat2gray(img_in);[h,w]=size(img_in);[row,col]=find(img_in>yu_value);%找到所有大于阈值的点,记录坐标l=length(row);a(1,:)=row;a(2,:)=col;fori0=1:hforj0=1:wfori=1:lc_store(i)=norm(a(:,i)-[i0;j0]);endmin_c(i0,j0)=min(c_store);endendmin_c_rang=mat2gray(min_c);img_out=img_in.*(1-min_c_rang);end888888888888888888888888888888888888888888888888888888888888888888888888888888888888distanceValueMap_search_onescalefunction[DistanceValue_t1,DistanceValue_exp,DistanceValue_t1_rang,DistanceValue_exp_rang]=distanceValueMap_search_onescale(img_in,max_side)%UNTITLED7Summaryofthisfunctiongoeshere%Detailedexplanationgoeshere[h,w]=size(img_in(:,:,1));img_scale1=img_in;%================================================================================%在计算块之前,考虑边缘点,所以先对矩阵进行填充q=3;%填充边缘像素个数img_scale1_pad(:,:,1)=padarray(img_scale1(:,:,1),[q,q],'replicate','both');img_scale1_pad(:,:,2)=padarray(img_scale1(:,:,2),[q,q],'replicate','both');img_scale1_pad(:,:,3)=padarray(img_scale1(:,:,3),[q,q],'replicate','both');% %计算该尺度下存储patch相量的矩阵,各三个像素取一个patchfori=1:hforj=1:wimg_scale1_patchVstore_all(i,j,:)=reshape(img_scale1_pad(i:i+6,j:j+6,:),1,147);endendimg_scale1_patchVstore_x=img_scale1_patchVstore_all(1:q:h,1:q:w,:);%将代表patch的相量存为一个矩阵disp('img_scale1_patchVstore_xcomplete');% %开始计算每一点的距离的值[h_x,w_x]=size(img_scale1_patchVstore_x(:,:,1));%记录存储矩阵的大小fori0=1:hdisp(num2str(i0));forj0=1:wtemp1=img_scale1_patchVstore_all(i0,j0,:);store_tp1_all=reshape(img_scale1_patchVstore_all(i0,j0,:),1,147);fori=1:h_xforj=1:w_xstore_tp1_x=reshape(img_scale1_patchVstore_x(i,j,:),1,147);store_o_disvalue_scale1_x(i,j)=norm(store_tp1_all-store_tp1_x);%将与mex_store_tp1像素和其他全图像素计算的欧式距离存储store_position_dis_x(i,j)=norm([i0,j0]-[(1+(i-1)*3),(1+(j-1)*3)]);endend%---将距离值进行归一化 max_1=max(max(store_o_disvalue_scale1_x));storemap_scale1_x_rang=mat2gray(store_o_disvalue_scale1_x,[0,max_1]);store_position_dis_x_rang=mat2gray(store_position_dis_x,[0,max_side]);%在0至U最大边长之间归一化%--结合相量值欧式距离和位置欧式距离,计算每个patch对于i0,j0的最终距离值 c=3;%设定该公式中的一个参数% 以下为该尺度中的距离值Dis_scale1=storemap_scale1_x_rang./(1+3*store_position_dis_x_rang);%--在上述该尺度的距离值中找距目标patch欧式距离最小的65个patch,并记录位置和欧式距离值-----Dis_all=Dis_scale1;num_K=65;%在矩阵中找65个最小值cout=0;%计数变量初始值min_v=[];%计数矩阵初始值whilecout<num_Kmm=min(min(Dis_all));f=find(Dis_all==mm);min_v=[min_v,Dis_all(f)'];cout=length(min_v);Dis_all(f)=10;endDistanceValue_t1(i0,j0)=sum(min_v)/num_K;DistanceValue_exp(i0,j0)=1-exp(-DistanceValue_t1(i0,j0));endend%对两个值进行归一化DistanceValue_t1_rang=mat2gray(DistanceValue_t1);DistanceValue_exp_rang=mat2gray(DistanceValue_exp);end888888888888.888888888888888888888888888888888888888888888888888888888888888888gaussianSmoothfunction[result]=gaussianSmooth(img)%UNTITLEDSummaryofthisfunctiongoeshere%Detailedexplanationgoeshere%将图像进行高斯平滑,用于生成高斯金字塔等或是去噪%采用横向,纵向两个向量平滑% filter=[1,5,10,10,5,1,1];filter=filter/sum(filter);[h,w]=size(img);ifmin(h,w)>3%bigimage-usestraight-forwardmethodresult=conv2(filter,filter,img,'same');%不进行降采样%horResult=convResult(:,[2:2:end]-1);%result=horResult([2:2:end]-1,:);else

%Imageissmallalongatleastonedimension.error('输入进行高斯平滑的图太小();endend5.RGB2Lab8888888888888888888888888888888888888888888888888888888888888888888888888888888888888function[L,a,b]=5.RGB2Lab%function[L,a,b]=RGB2Lab(R,G,B)%RGB2LabtakesmatricescorrespondingtoRed,Green,andBlue,and%transformsthemintoCIELab.ThistransformisbasedonITU-R%RecommendationBT.709usingtheD65whitepointreference.%TheerrorintransformingRGB->Lab->RGBisapproximately%10人-5.RGBvaluescanbeeitherbetween0and1orbetween0and255.%ByMarkRuzonfromCcodebyYossiRubner,23September1997.%UpdatedforMATLAB528January1998.%%Ifyourimageisloadedintouint8formatasanMxNx3tensor,you%canpassitinasoneargument.Ifyoubreakitinto3pieces,convert%themintodoublebeforecallingthisfunction.if(nargin==1)B=double(R(:,:,3));G=double(R(:,:,2));R=double(R(:,:,1));endif((max(max(R))>1.0)I(max(max(G))>1.0)I(max(max(B))>1.0))R=R/255;G=G/255;B=B/255;end[M,N]=size(R);=M*N;%SetathresholdT=0.008856;RGB=[reshape(R,1,s);reshape(G,1,s);reshape(B,1,s)];%RGBtoXYZMAT=[0.4124530.3575800.180423;0.2126710.7151600.072169;0.0193340.1191930.950227];XYZ=MAT*RGB;X=XYZ(1,:)/0.950456;Y=XYZ(2,:);Z=XYZ(3,:)/1.088754;XT=X>T;YT=Y>T;ZT=Z>T;fX=XT.*X.人(1/3)+(~XT).*(7.787.*X+16/116);%ComputeLY3=Y.A(1/3);fY=YT.*Y3+(~YT).*(7.787.*Y+16/116);L=YT.*(116*Y3-16.0)+(~YT).*(903.3*Y);fZ=ZT.*Z.人(1/3)+(~ZT).*(7.787.*Z+16/116);%Computeaandba=500*(fX-fY);b=200*(fY-fZ);L=reshape(L,M,N);a=reshape(a,M,N);b=reshape(b,M,N);if((nargout==1)I(nargout==0))L=cat(3,L,a,b);End8888888888888888888888888888888888888888888888888888888888888888888888888888888888pre_rgb2labfunction[img_lab]=pre_rgb2lab(img_in,max_side)%UNTITLED3Summaryofthisfunctiongoeshere%Detailedexplanationgoeshere%img_rgb:缩放后的rgb图%img_lab:rgb2lab后的图%h,w,图像高宽img=double(img_in);[h_t,w_t]=size(img(:,:,1));%得到原图的长宽ifw_t>h_t %看长和宽哪个比较大,将原图放缩至大值为250img_rgb(:,:,1)=imresize(img(:,:,1),[(max_side/w_t)*h_t,max_side],'bilinear');%用双线性差值法img_rgb(:,:,2)=imresize(img(:,:,2),[(max_side/w_t)*h_t,max_side],'bilinear');img_rgb(:,:,3)=imresize(img(:,:,3),[(max_side/w_t)*h_t,max_side],'bilinear');elseimg_rgb(:,:,1)=imresize(img(:,:,1),[max_side,(max_side/h_t)*w_t],'bilinear');img_rgb(:,:,2)=imresize(img(:,:,2),[max_side,(max_side/h_t)*w_t],'bilinear');img_rgb(:,:,3)=imresize(img(:,:,3),[max_side,(max_side/h_t)*w_t],'bilinear');end%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%=====================RGB2Lab=============================img_lab_o=RGB2Lab(img_rgb);img_lab(:,:,1)=img_lab_o(:,:,1)*255/100; %L通道从0到100转至l」0到255img_lab(:,:,2)=(img_lab_o(:,:,2)+120)*255/200;%a,通道从-120到120转到0到255img_lab(:,:,3)=(img_lab_o(:,:,3)+120)*255/200;%========================================================%归一化,从0到255归至U0到1img_lab=img_lab/255;end8888888888888888888888888888888888888888888888888888888888888888888888888888888888888Lab2RGBfunction[R,G,B]=Lab2RGB(L,a,b)%function[R,G,B]=Lab2RGB(L,a,b)%Lab2RGBtakesmatricescorrespondingtoL,a,andbinCIELabspace%andtransformsthemintoRGB.ThistransformisbasedonITU-R%RecommendationBT.709usingtheD65whitepointreference.%andtheerrorintransformingRGB->Lab->RGBisapproximately%10人-5.ByMarkRuzonfromCcodebyYossiRubner,23September1997.%UpdatedforMATLAB528January1998.%Fixedabuginconversionbacktouint89September1999.if(nargin==1)b=L(:,:,3);a=L(:,:,2);L=L(:,:,1);end%ThresholdsT1=0.008856;T2=0.206893;[M,N]=size(L);s=M*N;L=reshape(L,1,s);a=reshape(a,1,s);b=reshape(b,1,s);%ComputeYfY=((L+16)/116).人3;YT=fY>T1;fY=(-YT).*(L/903.3)+YT.*fY;丫=fY;%AlterfYslightlyforfurthercalculationsfY=YT.*(fY.人(1/3))+(〜YT).*(7.787.*fY+16/116);%ComputeXfX=a/500+fY;XT=fX>T2;X=(XT.*(fX.人3)+(-XT).*((fX-16/116)/7.787));%ComputeZfZ=fY-b/200;ZT=fZ>T2;Z=(ZT.*(fZ.人3)+(〜ZT).*((fZ-16/116)/7.787));X=X*0.950456;Z=Z*1.088754;MAT=[3.240479-1.537150-0.498535;-0.9692561.8759920.041556;0.055648-0.2040431.057311];RGB=max(min(MAT*[X;Y;Z],1),0);R=reshape(RGB(1,:),M,N)*255;G=reshape(RGB(2,:),M,N)*255;B=reshape(RGB(3,:),M,N)*255;if((nargout==1)I(nargout==0))R=uint8(round(cat(3,R,G,B)));End8888888888888888888888888888888888888888888888888888888888888888888888888888888get4Scalefunction[img_scale_1,img_scale_2,img_scale_3,img_scale_4]=get4Scale(img_in)%UNTITLED4Summaryofthisfunctiongoeshere%Detailedexplanationgoeshere********************************************************************************%1.scale_11img_scale_1=img_in;[h,w]=size(img_scale_1(:,:,1));%记录原始图像尺寸% %2.scale_20.8%以下缩放为最邻近差值img_scale_2_g(:,:,1)=gaussianSmooth(img_scale_1(:,:,1));%先每一层进行高斯平滑,模糊时使用原图img_scale_2_g(:,:,2)=gaussianSmooth(img_scale_1(:,:,2));img_scale_2_g(:,:,3)=gaussianSmooth(img_scale_1(:,:,3));img_scale_2(:,:,1)=imresize(img_scale_2_g(:,:,1),[h*0.8,w*0.8]);%图像缩小为第二尺度,0.8img_scale_2(:,:,2)=imresize(img_scale_2_g(:,:,2),[h*0.8,w*0.8]);img_scale_2(:,:,3)=imresize(img_scale_2_g(:,:,3),[h*0.8,w*0.8]);% %3.scale_30.5img_scale_3_g(:,:,1)=gaussianSmooth(img_scale_2(:,:,1));%先每一层进行高斯平滑,模糊时使用放缩0.8的图作为原图img_scale_3_g(:,:,2)=gaussianSmooth(img_scale_2(:,:,2));img_scale_3_g(:,:,3)=gaussianSmooth(img_scale_2(:,:,3));img_scale_3(:,:,1)=imresize(img_scale_3_g(:,:,1),[h*0.5,w*0.5]);%图像缩小为第3尺度,0.5img_scale_3(:,:,2)=imresize(img_scale_3_g(:,:,2),[h*0.5,w*0.5]);img_scale_3(:,:,3)=imresize(img_scale_3_g(:,:,3),[h*0.5,w*0.5]);% %4.scale_40.3img_scale_4_g(:,:,1)=gaussianSmooth(img_scale_3(:,:,1));%先每一层进行高斯平滑,模糊时使用放缩后的尺度0.5作为原图img_scale_4_g(:,:,2)=gaussianSmooth(img_scale_3(:,:,2));img_scale_4_g(:,:,3)=gaussianSmooth(img_scale_3(:,:,3));img_scale_4(:,:,1)=imresize(img_scale_4_g(:,:,1),[h*0.3,w*0.3]);%图像缩小为第4尺度,0.3img_scale_4(:,:,2)=imresize(img_scale_4_g(:,:,2),[h*0.3,w*0.3]);img_scale_4(:,:,3)=imresize(img_scale_4_g(:,:,3),[h*0.3,w*0.3]);end8888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888distanceValueMap_search_onescale_2function[DistanceValue_t1,DistanceValue_exp,DistanceValue_t1_rang,DistanceValue_exp_rang]=distanceValueMap_search_onescale_2(img_in,max_side)%UNTITLED7Summaryofthisfunctiongoeshere%Detailedexplanationgoeshere[h,w]=size(img_in(:,:,1));img_scale1=img_in;%================================================================================%在计算块之前,考虑边缘点,所以先对矩阵进行填充q=3;%填充边缘像素个数img_scale1_pad(:,:,1)=padarray(img_scale1(:,:,1),[q,q],'replicate','both');img_scale1_pad(:,:,2)=padarray(img_scale1(:,:,2),[q,q],'replicate','both');img_scale1_pad(:,:,3)=padarray(img_scale1(:,:,3),[q,q],'replicate','both');% %计算该尺度下存储patch相量的矩阵,各三个像素取一个patchfori=1:hforj=1:wimg_scale1_patchVstore_all(i,j,:)=reshape(img_scale1_pad(i:i+6,j:j+6,:),1,147);endendimg_scale1_patchVstore_x=img_scale1_patchVstore_all(1:q:h,1:q:w,:);%将代表patch的相量存为一个矩阵ones_Vstore_temp=ones(size(img_scale1_patchVstore_x));%生成全一矩阵disp('img_scale1_patchVstore_xcomplete');% %开始计算每一点的距离的值[h_x,w_x]=size(img_scale1_patchVstore_x(:,:,1));%记录存储矩阵的大小fori0=1:hdisp(num2str(i0));forj0=1:wtemp1=img_scale1_patchVstore_all(i0,j0,:);fori2=1:length(temp1)temp_x_1(:,:,i2)=temp1(:,:,i2)*ones_Vstore_temp(:,:,i2);endtemp_x_2=temp_x_1-img_scale1_patchVstore_x;temp_x_2=temp_x_2.*tem

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

最新文档

评论

0/150

提交评论