📄 image_encode.m
字号:
%
% function [reconstruct_image,frequency] = image_encode(image_data,cdbk):
% Encode each image using given codebook
%
% Input: image_data -- N*n_features, a matrix to represents an image,
% each row represents a block
% cdbk -- nwds*n_features matrix, codebook for image encoding
% Output:
% compressed_image -- nwds*1, represents a compressed 2D image, each
% item is an index of the cdbk
% reconstruct_image -- N*n_features matrix, the reconstructed image
% using keyblocks
% frequency -- 1*nwds the number of each cdword used in
% reconstruction
%
function [compressed_image,reconstruct_image,frequency] = image_encode(image_data,cdbk)
n_point = size(image_data,1);
nwds = size(cdbk, 1);
frequency = zeros(1,nwds);
for i_point = 1: n_point
% get the vector of one point
p = image_data(i_point);
% partition this point into one region based on nearest
% neighbor condition
% initialize the parameter to be impractical
mindis = Inf;
index_nwds = 0;
for ic = 1: nwds
cw = cdbk(ic,:);
dis = my_distance(p,cw);
if dis < mindis
mindis = dis;
index_nwds = ic;
end
end
% encode current feature using nearest codeword
compressed_image(i_point) = index_nwds;
reconstruct_image(i_point,:) = cdbk(index_nwds,:);
frequency(index_nwds) = frequency(index_nwds)+1;
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -