I have an image and I need to extract local features,so I divided it to 16 blocks and size of each block =64 *64 pixels and extract that three color histograms features locally from each block, now I need to

2 次查看(过去 30 天)
tic
disp('query')
[filename, pathname]=uigetfile({'*.jpg'},'queryimage');
img=strcat(pathname,filename);
a=imread(img);
subplot(4,5,3)
imshow(img)
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0.05 1 0.95]);
[r, c, numOfBands] = size(a);
%dividing image into 8x8 subblocks
bs=64;%block size
nob=(r/bs)*(c/bs);%Total no of blocks
k=0;
for i=1:(r/bs)
for j=1:(c/bs)
T=k+j;
T=num2str(T);
C=strcat(b,T);
col1=bs*(j-1)+1;
row1=bs*(i-1)+1;
col2=bs*(j-1)+bs;
row2=bs*(i-1)+bs;
C=imcrop(a,[col1 row1 col2 row2]);
end
k=k+(r/bs);
end
b = rgb2hsv(b);
% split image into h, s & v planes
h = b(:, :, 1);
s = b(:, :, 2);
v = b(:, :, 3);
% Create the histogram quantized into 8×3×3 bins
X= zeros(8, 3, 3);
for k = 1 : numel(h)
indexH = floor(8 * h(k)) + 1;
indexS = floor(3 * s(k)) + 1;
indexV = floor(3 * v(k)) + 1;
if indexH > 8
indexH = 8;
end
if indexS > 3
indexS = 3;
end
if indexV > 3
indexV = 3;
end
X(indexH, indexS, indexV) = X(indexH, indexS, indexV) + 1;
end
#so, i want to quantify each block in the above manner i want to do for every block and store the 16 blocks matrices into resultant matrix G, how i do that
  1 个评论
Walter Roberson
Walter Roberson 2018-1-24
You have
for i=1:(r/bs)
for j=1:(c/bs)
T=k+j;
T=num2str(T);
C=strcat(b,T);
col1=bs*(j-1)+1;
row1=bs*(i-1)+1;
col2=bs*(j-1)+bs;
row2=bs*(i-1)+bs;
C=imcrop(a,[col1 row1 col2 row2]);
end
k=k+(r/bs);
end
Every iteration of j, you write over all of the C matrix, so at the end, C is just going to be the result of executing the last i and last j

请先登录,再进行评论。

采纳的回答

Image Analyst
Image Analyst 2018-1-24
Try
k = 1;
for i=1:(r/bs)
for j=1:(c/bs)
% code snipped....
C{k} = imcrop(a,[col1 row1 col2 row2]);
k = k + 1;
end
end

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Computer Vision with Simulink 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by