如何在MATLAB中显示多级wavedec2

时间:2017-11-27 22:29:31

标签: matlab image-processing dwt wavelet-transform

在计算图像的4级离散小波变换后,如何在matlab中显示这种多级变换? 如何绘制相应DWT系数的直方图?

这是我到目前为止所做的:

Dim finalrow As Long
finalrow = Worksheets("Redundancy").Cells(Worksheets("Redundancy").Rows.Count, "D").End(xlUp).Row
Dim z As Long
Dim color As Integer
color = 3
Dim smrownumber As Integer
Dim arownumber As Integer
Dim across As Integer
Dim CellA As String
Dim match As String
Dim CellB As String
Dim change As Integer
Dim First As Integer
Dim Second As Integer
Dim FirstLast As Integer
Dim SecondLast As Integer
For z = 2 To finalrow
    If Cells(2 + z, 9).Value = Cells(3 + z, 9).Value And Cells(2 + z, 10).Value <> Cells(3 + z, 10).Value Then
        First = z + 2
        FirstLast = First + 1
    End If
    If z <> 2 Then
        If Cells(2 + z, 9).Value = Cells(3 + z, 9).Value And Cells(2 + z, 11).Value <> Cells(3 + z, 11).Value Then
            Second = z + 2
            SecondLast = Second + 1
        End If
        Else
            Second = z + 2
            SecondLast = 2
    End If
        For arownumber = SecondLast To First 'need to find the rownumbers that we compare with
            For change = 4 To 7
                For smrownumber = FirstLast To Second 'need to find the rownumbers for comparing
                    For across = 4 To 7
                        CellA = Cells(arownumber, change)
                        CellB = Cells(smrownumber, across)
                        match = IIf(CellA = CellB, "yes", "no")
                        If match = "yes" Then
                            Cells(arownumber, change).Interior.ColorIndex = color
                            Cells(smrownumber, across).Interior.ColorIndex = color
                            color = color + 1
                        End If
                    Next across
                Next smrownumber
            Next change
        Next arownumber
 Next z

1 个答案:

答案 0 :(得分:1)

这就是我要做的事情:

N = 4;

img = imread('image.png');
img = im2double(img);

[C,S] = wavedec2(img,N,'haar');

for i = 1:N
    lvl = ['Level ' num2str(i)];

    A = appcoef2(C,S,'haar',i);
    [H,V,D] = detcoef2('all',C,S,i);

    figure('Name',['Images (' lvl ')']);
    % Eventually, you can define a colormap for your images...
    % colormap(pink(255));
    subplot(2,2,1); imagesc(A);
    title('Approximation')
    subplot(2,2,2); imagesc(H);
    title('Horizontal Detail');
    subplot(2,2,3); imagesc(V);
    title('Vertical Detail');
    subplot(2,2,4); imagesc(D);
    title('Diagonal Detail'); 
    suptitle(lvl);

    % tweak the histogram bins as you prefer
    figure('Name',['Histograms (' lvl ')']);
    subplot(2,2,1); hist(A(:),32);
    subplot(2,2,2); hist(H(:),32);
    subplot(2,2,3); hist(V(:),32);
    subplot(2,2,4); hist(D(:),32);
    suptitle(lvl);
end

实际上,由于我对数字图像处理不太熟悉,因此您可以调整我的示例并使其符合您的需求。