i used the below code for image retrival through corel database but my results are not upto the mark,please verify my node and let me get your help to make necessary corrections,I use local color feature
3 views (last 30 days)
Show older comments
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)
col1=bs*(j-1)+1;
row1=bs*(i-1)+1;
col2=bs*(j-1)+bs;
row2=bs*(i-1)+bs;
C{k+j}=imcrop(a,[col1 row1 col2 row2]);
end
k=k+(r/bs);
end
for i=1:nob
D = rgb2hsv(C{i});
% split image into h, s & v planes
h = D(:, :, 1);
s = D(:, :, 2);
v = D(:, :, 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
x{i}=X;
end
disp('database')
CP=zeros(1,999);
str='.jpg';
for z=1:999
b=num2str(z);
c=strcat(b,str);
a=imread(c);
[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)
col1=bs*(j-1)+1;
row1=bs*(i-1)+1;
col2=bs*(j-1)+bs;
row2=bs*(i-1)+bs;
C{k+j}=imcrop(a,[col1 row1 col2 row2]);
end
k=k+(r/bs);
end
for i=1:nob
D = rgb2hsv(C{i});
% split image into h, s & v planes
h = D(:, :, 1);
s = D(:, :, 2);
v = D(:, :, 3);
% Create the histogram quantized into 8×3×3 bins
Y= 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
Y(indexH, indexS, indexV) = Y(indexH, indexS, indexV) + 1;
end
y{i}=Y;
end
for i=1:nob
CP(z)=euclideanDistance(x{i}, y{i});
CP(z)=CP(z)+1;
end
end
B=sort(CP);
for z=1:999
for M=1:12
if(CP(z)==B(M))
subplot(5,3,M+3)
z=num2str(z);
imshow(strcat(z,str))
end
end
end
disp('retrived')
toc
9 Comments
Walter Roberson
on 25 Jan 2018
"Please let me know if you could help me with this or not"
No, you appear to need the solution faster than I can provide it, because I need to sleep at night. You had better hire a team of consultants.
Answers (2)
Walter Roberson
on 25 Jan 2018
- Your logic for indexing when you store the cropped images was not correct.
- You were failing to add in the pathname when you imread() and imshow()
- You were not pre-allocating arrays. This is a weakness rather than an outright error
- You were asking to imcrop by start and ending indices. imcrop() expects width and height, not ending indices.
- imcrop has a known weakness that is often overlooked: if you are not at the right edge then imcrop extracts one column more than it should, and if you are not at the bottom edge then imcrop extracts one row more than it should.
I have attached cleaned up code.
I am not able to test this further as routine euclideanDistance is not defined.
7 Comments
See Also
Categories
Find more on Computer Vision with Simulink in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!