| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 519 人关注过本帖
标题:子程序运行不了,不知道怎么调试?
只看楼主 加入收藏
liguo1989
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2011-5-17
收藏
 问题点数:0 回复次数:0 
子程序运行不了,不知道怎么调试?

img=imread('E:\yzh\hftp.jpg');%读入原图像
img_0=rgb2gray(img);
img_1=imnoise(img_0,'salt & pepper',0.02);
img_2=medfilt2(img_1);%中值滤波
subplot(2,2,1);imshow(img);title('原始图像');
subplot(2,2,2);imshow(img_0);title('灰度图像');
subplot(2,2,3);imshow(img_1);title('椒盐噪声');
figure;
imshow(img_2);title('中值滤波后图像');
 
hz=fspecial('log');
t=imfilter(img_2,hz);
BW=edge(t,'prewitt');
figure;
imshow(t);title('锐化');
imshow(BW);title('边缘提取');

%裁剪图像

J=imcrop(BW,[100 75 500 275]);
imwrite(J,'BW_part.jpg');
X=imread('BW_part.jpg');
imshow(X);title('剪切图片');

%图像压缩

[r,c]=size(X);%图像尺寸
A=double(X);%转换双精度
T=dctmtx(8);%离散余弦变换矩阵
B=blkproc(A,[8 8],'P1*x*P2',T,T');
%对原图像进行DCT变换
mask=[1 1 1 1 0 0 0 0
      1 1 1 0 0 0 0 0
      1 1 0 0 0 0 0 0
      1 0 0 0 0 0 0 0
      0 0 0 0 0 0 0 0
      0 0 0 0 0 0 0 0
      0 0 0 0 0 0 0 0
      0 0 0 0 0 0 0 0];
B2=blkproc(B,[8 8],'P1*x',mask);
%数据压缩,丢弃右下角高频数据
M=blkproc(B2,[8 8],@lianghua);%量化
%imshow(M);
%huffman编码
H=huff06get(M)
%huffman解码
f=Huff06put(H)
N=reshape(f,r,c);
N =N+minM;

T=blkproc(N,[8 8],@ilianghua); %反量化
I=blkproc(T,[8 8],@idct2); %8*8DCT反变换

%图像重建

I=uint8(I);
imshow(X);
axis square;xlabel('原图像');
imshow(I);
axis square;xlabel('压缩图像');
 


 


function  H=huff06get(M)
[m,n]=size(M);
re=m*n;
p=zeros(1,61);
for t=1:61
    count=0;
    for i=1:m
        for j=1:n
            if M(i,j)==t-1
                count=count+1;
            end
        end
    end
    p(t)=count;p0=p;
end
core=cell(61,1);
sign=zeros(61);
for hh=1:60
   
    for t=1:61
        if (p(t)<re)&(p(t)>0)
            re=p(t);
        end
    end
    t=1;
    while (p(t)~=re)&(t<61)
        t=t+1;
    end
    if sign(t,1)==0
        core{t}='0';
    else
        core{t}=['0',core{t}];
        i=1;
        while (sign(t,i)~=0)&(i<61)
            core{sign(t,i)}=['0',core{sign(t,i)}];
            i=i+1;
        end
    end
    p(t)=0;
    cou=t;
    re1=m*n;
    for t=1:61
        if (p(t)<re1)&(p(t)>0)
            re1=p(t);
        end
    end
    t=1;
    while (p(t)~=re1)&(t<61)
        t=t+1;
    end
    if sign(t,1)==0
        core{t}='1';
    else
        core{t}=['1',core{t}];
        i=1;
        while (sign(t,i)~=0)&(i<61)
            core{sign(t,i)}=['1',core{sign(t,i)}];
            i=i+1;
        end
    end
    p(t)=p(t)+re;
    cou1=t;
    i=1;
    while (sign(t,i)~=0)&(i<61)
        i=i+1;
    end
    sign(t,i)=cou;
    i=i+1;
    j=1;
    while (sign(cou,j)~=0)&(j<61)
        sign(t,i)=sign(cou,j);
        i=i+1;
        j=j+1;
    end
end  %产生huffman码
Mc=cell(m,n);
for i=1:m
    for j=1:n
        if (M(i,j)<61)&(M(i,j)>0)
            Mc{i,j}=core{M(i,j)+1};
        else
            Mc{i,j}='0';
        end
    end
end
imcore=char2cell[1,re];
for i=1:m
    for j=1:n
        imcore=[imcore,Mc{i,j}];
    end
end
  
save picture imcore core; %保存图片码流和编码对应表


   
  function f=Huff06put(H)
clear;
Nc=size(core);
Nic=size(imcore);
flag=0;
i=1;
j=1;
q=1;
cz=char2cell();
f=zeros(128);
for q=1:400930
    if flag==0
        cz=[cz,imcore(q)];
    else
        cz=imcore(q);
        flag=0;
    end
    for t=1:(s-1)
        if strcmp(cz,core{t})
            f(j,i)=t;
            flag=1;
            if i>127;
                i=1;
                j=j+1;
            else
                i=i+1;
            end
            break;
        end
    end
end
f=uint8(f*4+35);
  
   
   
   
   
   
搜索更多相关主题的帖子: 子程序 
2011-05-18 09:08
快速回复:子程序运行不了,不知道怎么调试?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.011550 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved