0

我有一个使用小波变换和颜色直方图的 CBIR 项目。我对 Singha 和 Hemachandran 的研究进行了重新实验。我尝试对其进行编码,但是当将图像添加到数据库中时,它一直是错误的。错误消息指出:

Error using database/fastinsert (line 222)
Cell array or struct should not contain vectors

Error in koneksidbEkstraksi (line 11)
fastinsert(conn, 'ekstraksifitur', colciri, rowciri);

Error in metode_ekstraksi (line 157)
koneksidbEkstraksi(A, H, V);

Error in tambah>btn_tmbhcitra_Callback (line 361)
        metode_ekstraksi(input);

Error in gui_mainfcn (line 96)
        feval(varargin{:});

Error in tambah (line 42)
    gui_mainfcn(gui_State, varargin{:});

Error in
@(hObject,eventdata)tambah('btn_tmbhcitra_Callback',hObject,eventdata,guidata(hObject))


Error while evaluating uicontrol Callback

我认为这是由提取代码的算法引起的。这是代码。

function metode_ekstraksi(citra)
%extract component of RGB
r = citra(:,:,1);
g = citra(:,:,2);
b = citra(:,:,3);

%decompose each Red, Green, Blue component
[R,SR] = wavedec2(r,1,'db2');
LL1R = appcoef2(R,SR,1,'db2');
[HL1R,LH1R,HH1R] = detcoef2('all',R,SR,1);
[G,SG] = wavedec2(g,1,'db2');
LL1G = appcoef2(G,SG,1,'db2');
[HL1G,LH1G,HH1G] = detcoef2('all',G,SG,1);
[B,SB] = wavedec2(b,1,'db2');
LL1B = appcoef2(B,SB,1,'db2');
[HL1B,LH1B,HH1B] = detcoef2('all',B,SB,1);

%combine approximate, horizontal, vertical coefficient of RGB component
A1(:,:,1) = LL1R;
A1(:,:,2) = LL1G;
A1(:,:,3) = LL1B;
H1(:,:,1) = HL1R;
H1(:,:,2) = HL1G;
H1(:,:,3) = HL1B;
V1(:,:,1) = LH1R;
V1(:,:,2) = LH1G;
V1(:,:,3) = LH1B;

%assign the weights
BA = 0.003*A1;
BH = 0.001*H1;
BV = 0.001*V1;

[rowsA, colsA, numOfBands] = size(BA);
[rowsH, colsH, numOfBands] = size(BH);
[rowsV, colsV, numOfBands] = size(BV);
%convert coefficient into hsv plane
hsvA = rgb2hsv(BA);
ha = hsvA(:, :, 1);
sa = hsvA(:, :, 2);
va = hsvA(:, :, 3);
hsvH = rgb2hsv(BH);
hh = hsvH(:, :, 1);
sh = hsvH(:, :, 2);
vh = hsvH(:, :, 3);
hsvV = rgb2hsv(BV);
hv = hsvV(:, :, 1);
sv = hsvV(:, :, 2);
vv = hsvV(:, :, 3);

% Specify the number of quantization levels.
numberOfLevelsForH = 8;
numberOfLevelsForS = 8;
numberOfLevelsForV = 8;

% Find the max.
maxValueForHa = max(ha(:));
maxValueForSa = max(sa(:));
maxValueForVa = max(va(:));
maxValueForHh = max(hh(:));
maxValueForSh = max(sh(:));
maxValueForVh = max(vh(:));
maxValueForHv = max(hv(:));
maxValueForSv = max(sv(:));
maxValueForVv = max(vv(:));

% create final histogram matrix of size 8x2x2
A = zeros(8, 8, 8);
H = zeros(8, 8, 8);
V = zeros(8, 8, 8);

% create col vector of indexes for later reference
indexA = zeros(rowsA*colsA, 3);
indexH = zeros(rowsH*colsH, 3);
indexV = zeros(rowsV*colsV, 3);

% Put all pixels into one of the "numberOfLevels" levels.
count = 1;
for rowA = 1:size(ha, 1)
    for colA = 1 : size(ha, 2)
        quantizedValueForHa(rowA, colA) = ceil(numberOfLevelsForH * ha(rowA, colA)/maxValueForHa);
        quantizedValueForSa(rowA, colA) = ceil(numberOfLevelsForS * sa(rowA, colA)/maxValueForSa);
        quantizedValueForVa(rowA, colA) = ceil(numberOfLevelsForV * va(rowA, colA)/maxValueForVa);

        % keep indexes where 1 should be put in matrix hsvHist
        indexA(count, 1) = quantizedValueForHa(rowA, colA);
        indexA(count, 2) = quantizedValueForSa(rowA, colA);
        indexA(count, 3) = quantizedValueForVa(rowA, colA);
        countA = count+1;
    end
end
for rowH = 1:size(hh, 1)
    for colH = 1 : size(hh, 2)
        quantizedValueForHh(rowH, colH) = ceil(numberOfLevelsForH * hh(rowH, colH)/maxValueForHh);
        quantizedValueForSh(rowH, colH) = ceil(numberOfLevelsForS * sh(rowH, colH)/maxValueForSh);
        quantizedValueForVh(rowH, colH) = ceil(numberOfLevelsForV * vh(rowH, colH)/maxValueForVh);

        % keep indexes where 1 should be put in matrix hsvHist
        indexH(count, 1) = quantizedValueForHh(rowH, colH);
        indexH(count, 2) = quantizedValueForSh(rowH, colH);
        indexH(count, 3) = quantizedValueForVh(rowH, colH);
        countH = count+1;
    end
end
for rowV = 1:size(hv, 1)
    for colV = 1 : size(hv, 2)
        quantizedValueForHv(rowV, colV) = ceil(numberOfLevelsForH * hv(rowV, colV)/maxValueForHv);
        quantizedValueForSv(rowV, colV) = ceil(numberOfLevelsForS * sv(rowV, colV)/maxValueForSv);
        quantizedValueForVv(rowV, colV) = ceil(numberOfLevelsForV * vv(rowV, colV)/maxValueForVv);

        % keep indexes where 1 should be put in matrix hsvHist
        indexV(count, 1) = quantizedValueForHv(rowV, colV);
        indexV(count, 2) = quantizedValueForSv(rowV, colV);
        indexV(count, 3) = quantizedValueForVv(rowV, colV);
        countV = count+1;
    end
end

% put each value of h,s,v to matrix 8x2x2
% (e.g. if h=7,s=2,v=1 then put 1 to matrix 8x2x2 in position 7,2,1)
for rowA = 1:size(indexA, 1)
    if (indexA(rowA, 1) == 0 || indexA(rowA, 2) == 0 || indexA(rowA, 3) == 0)
        continue;
    end
    A(indexA(rowA, 1), indexA(rowA, 2), indexA(rowA, 3)) = ... 
        A(indexA(rowA, 1), indexA(rowA, 2), indexA(rowA, 3)) + 1;
end
for rowH = 1:size(indexH, 1)
    if (indexH(rowH, 1) == 0 || indexH(rowH, 2) == 0 || indexH(rowH, 3) == 0)
        continue;
    end
    H(indexH(rowH, 1), indexH(rowH, 2), indexH(rowH, 3)) = ... 
        H(indexH(rowH, 1), indexH(rowH, 2), indexH(rowH, 3)) + 1;
end
for rowV = 1:size(indexV, 1)
    if (indexV(rowV, 1) == 0 || indexV(rowV, 2) == 0 || indexV(rowV, 3) == 0)
        continue;
    end
    V(indexV(rowV, 1), indexV(rowV, 2), indexV(rowV, 3)) = ... 
        V(indexV(rowV, 1), indexV(rowV, 2), indexV(rowV, 3)) + 1;
end

% normalize hsvHist to unit sum
A = A(:)';
A = A/sum(A);
H = H(:)';
H = H/sum(H);
V = V(:)';
V = V/sum(V);

koneksidbEkstraksi(A, H, V);

在此之前,我还展示了提取结果的数据库连接代码。这是代码。

function koneksidbEkstraksi(App, Hor, Ver)
conn=database('cbir018','root','');

Cciri = exec(conn, 'select max(kd_ekstraksi)+1 from ekstraksifitur');
Cciri = fetch(Cciri);
%Cciri.Data
kd=Cciri.Data{1,1};

colciri = {'kd_ekstraksi' 'koe_app' 'koe_hor' 'koe_ver'};            
rowciri = {kd, App, Hor, Ver};
fastinsert(conn, 'ekstraksifitur', colciri, rowciri);

close(conn);

我希望任何人都可以帮助我解决这个问题。谢谢你。

4

0 回答 0