資源簡介
用matlab實現了小波變換對圖像的分割
代碼片段和文件信息
close?all;
clc;
clear?all;
%%wavelet?transform?used?to?segment?an?image
?[FileName1PathName1]?=?uigetfile(‘*.jpg;*.tif;*.bmp;*.png‘‘請輸入訓練圖像‘);%讀入訓練樣本
?Im?=?fullfile(PathName1FileName1);
?Image=?imread(Im);???????????????%訓練的原始圖像,即網絡的輸入信號P
?subplot(231)imshow(Image);title(‘Original?Image‘);
Image=Image(::1);
?Image=double(Image)
[MN]=size(Image);
w?=?8*ones(1M/8);
h=?8*ones(1N/8);
B?=?mat2cell(Imagewh);
e=zeros(M/8N/8);
for?i=1:M/8
????for?j=1:N/8
????????[cs]=wavedec2(B{ij}2‘db3‘);?
????????ca1=appcoef2(cs‘db3‘1);
????????ch1=detcoef2(‘h‘cs1);
????????cv1=detcoef2(‘v‘cs1);
????????cd1=detcoef2(‘d‘cs1);
????????ca2=appcoef(cs‘db3‘2);
????????ch2=detcoef2(‘h‘cs2);
????????cv2=detcoef2(‘v‘cs2);
????????cd2=detcoef2(‘d‘cs2);
????????e_h1=sum(sum(ch1.^2));
????????e_v1=sum(sum(cv1.^2));
????????e_d1=sum(sum(cd1.^2));
????????e_a2=sum(sum(ca2.^2));
????????e_h2=sum(sum(ch2.^2));
????????e_v2=sum(sum(cv2.^2));
????????e_d2=sum(sum(cd2.^2));??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
評論
共有 條評論