hi, please I'm doing my project about image processing and I want to calculate the distance between the query image and the images in the base, I try this code but it didn't work, I appreciate any help

r1=a(:,:,1);
v1=a(:,:,2);
b1=a(:,:,3);
couleur1=(r1+v1+b1)/3;
i1 = rgb2gray(a);
t1=glcm(i1);
I1=invmoments(a);
X1={(couleur1),(t1),(I1)};
j=1;
projectdir = 'index\fusion';
list = dir(projectdir);
list([list.isdir]) = [];
filenames = natsort( {list.name});
for K = 1 : length(filenames)
ch = filenames{K};
nomImage = fullfile(projectdir, ch);
storedStructure = load (nomImage);
data{K} = storedStructure.X;
valeur = isequal(data{K},X1); end

Antworten (1)

You measured some things producing couler1, t1, and I1, but you do not appear to have defined any way of calculating a "distance" between these and equivalent stored values for any particular image.
Even if you are thinking of "Euclidean distance" you need to consider: are these values even on the same scale? If there is a contribution to the distance of 10 units from the colour portion, should that count the same as a distance of 10 units from the glcm portion?
If you took the RGB image and added 1 to every pixel component, resulting in a coleur1 array that was 1 higher at each location, the total difference over an M x N array would be (M * N), but the glcm might be exactly the same and the image moments might be exactly the same, contributing 0 from each. On the other hand, you could take a subsection of the original image and change it notably, such that the total change in colour was less than M*N but the glcm and image moments are fairly different: do you really want minor changes in colour to outweigh the other two components just because the image has so many more locations to contribute from than the glcm or image moments do?

12 Kommentare

my goal is to amalgamate the three color characteristics color , shape and texture that's why I do like this
That's nice, but you did not answer any of my questions.
Your maximum color difference would be pure black (all 0) to pure white (all 255), so for an M x N array that could be 255 * M * N * 3 or 255 * sqrt(M * N * 3) or 255 * M * N * sqrt(3) depending how you calculate your Euclidean.
Your GLCM has a maximum contribution of... what?
Your image moments have a maximum contribution of... what?
Now how do you want to weight those three components to arrive at an overall score?
color [a b]=[256 384]
GLCM=[1 16]
moments =[1 7]
I want to find a way to compare query image using this three characteristics together to find the similar images in the base
Those appear to be sizes, not value ranges. What is the largest and smallest value for each of those items?
And why is your color 2 dimensional instead of 3 dimensional?
I suspect the largest value for GLCM could be 256 * (384-1) = 98048, for the case where all the values were the same. Is that correct?
You have a certain contribution to the "distance" from the color. For the moment, call that contribution C, and call the contribution for the GLCM G and call the contribution from the moments M. C, G, M. Now what relative importance do you wish to give those three? Should a difference in moments, M, be (say) 5 times as important as a difference in color, C ?
Consider
A1 = kron(ones(128, 192), eye(2));
This is a checkboard pattern. Now consider
A2 = fliplr(A1);
This is a checkboard pattern as well, the same image contents flipped left to right. But everywhere there was a 1 is now 0 and everywhere there was 0 is now 1, so every color is maximum difference. The GLCM of the two is going to be the same (to within +/- 1). The moments are going to be the same because moments are invariant to rotation and reflection for a symmetric matrix. The difference in color is going to be 256 * 384 = 98304 summed over all of the array elements. Now, what "distance" do you want this to be calculated as? Now compare A1, the original checkerboard, to
A3 = kron(eye(2), ones(128, 192));
This is a block pattern, top left and bottom right all white, top right and bottom left all black. This differs from A1 in half as many positions, so a contribution of 49152 from color distance. The GLCM is clearly going to be much different, but it has only 16 elements, and the image moments are going to be much different but they have only 7 elements. If you weight the G and M the same way you weight the C, then the 98304 color difference for the checkerboard is probably going to far outweigh the only 49152 difference in color for the block. Is that what you want, that an image that has the same content flipped top to bottom should measure as being far greater "distance" than an image that is visually completely different but whose color arrangement turns out to have a lower count?
The way you calculate the distance matters, and the way you weight the contribution of the C, G, M matters for determining "distance".
really I don't understand any thing, can you more explain it to me and thank you
Maybe you need to do some background study in CBIR. That's Content Based Image Retrieval. Basically you measure a bunch of things in an image and create a list of them, called a "feature vector". Then you compare the feature vector of that image with a generalized distance metric to the feature vector of other images in your collection (database) to see which other images have distances that are low, meaning they have a lot of features that match your query/test image.
I'm doing my project about image processing and I perform a search by color,shape and texture and now I want to merge this three characteristics to make my search better, I tried this algorithm but I don't get any result that's why if someone has an idea about this give it to me and thank you again
Will your searches always result in exact matches? Or do you need to find the "closest" match that probably will not be identical? If you want the closest match, then is color more important than texture or is texture more important than color? What should their relative importances be? What should be the relative importance of the image moments?
color is more important than the other I'll give the same importance for all the characteristic
In your code above, replace
valeur = isequal(data{K},X1)
by
dist(K) = sqrt( sum( ((double(data{K}{1}(:)) - double(X1{1}(:))) + (double(data{K}{2}(:)) - double(X1{2}(:))) + (double(data{K}{3}(:)) - double(X1{3}(:)))).^2 ) );
Then after the "for K" loop,
[mindist, minidx] = min(dist);
best_match_file = filenames{minidx};
I get this erreur : Error using + Matrix dimensions must agree.
dist(K) = sqrt( sum( cellfun(@(Data, x1) sum((double(Data{1}(:)) - double(x1(:))).^2), data{K}, X1) ) );

Melden Sie sich an, um zu kommentieren.

Gefragt:

am 9 Apr. 2016

Kommentiert:

am 17 Apr. 2016

Community Treasure Hunt

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

Start Hunting!

Translated by