image classification using fourier transform

I can get the Fourier transform frequency domain using the MATLAB fft2() code, but I want to get the highest spectrum magnitudes and the DC. What should I do?
The purpose is to :
  1. Get the frequency domain representation F(U,v) of g(x,y) using Fourier Transform.
  2. What is the DC value of (u,v)?
  3. Select the three highest spectrum magnitudes as the image’s signature vector.
  4. Obtain the signature vector for each image in each class.
  5. Use nearest neighbor to assign f(u,v) to its closest class.
I found this code that gets the magnitude:
% Perform 2D FFTs
fftA = fft2(double(imageA));
% Display magnitude and phase of 2D FFTs
figure
imshow(abs(fftshift(fftA)),[24 100000]);
colormap gray
title('Image A FFT2 Magnitude')

 채택된 답변

Image Analyst
Image Analyst 2016년 12월 10일
편집: Image Analyst 2016년 12월 10일

3 개 추천

If you want the max, call max():
fftMagnitude = abs(fftshift(fftA));
maxValue = max(fftMagnitude(:));
Doing that will not find two images that match though. Unless they match exactly, i.e. it's the very same image.
For what it's worth, I've attached assorted fft demo programs, though they aren't doing image matching like you want. You might use immse() or psnr() or something like that if you want to find matching images. Though that won't do CBIR if that's what you're after.

댓글 수: 15

raymon hani
raymon hani 2016년 12월 10일
편집: Image Analyst 2016년 12월 10일
Thanks a lot for the clarification now i understand the max part .. just to clarify i am asked to :
  1. Get the frequency domain representation F(U,v)of g(x,y)using Fourier Transform.
  2. What is the DC value of (u,v)?
  3. Select the three highest spectrum magnitudes as the image’s signature vector.
  4. Obtain the signature vector for each image in each class.
  5. Use nearest neighbor to assign f(u,v) to its closest class..
The attached program unfortunately is very advanced to my knowledge of Mat lab. So if you can explain this in a simple way as i am given 4 classes of (1,2,3,4 numbers),each class has 3 images of the same number in a different style and the g(X,Y) is the needed to detect which class does it belongs to .
1 is simply
F = fft2(g);
2 is
DCValue = F(1,1);
3 is
fftMag = abs(F);
sortedMags = sort(fftMag, 'descend');
threeHighest = sortedMags(1:3);
4 means do 1-3 for all your images.
Not sure what 5 means, but it's like maybe there were some images you weren't supposed to know what class they were, like the images in #4 where you knew what class they were. So then you have to examine the 3 element magnitudes vector you got in #3 to try to decide what class the unknown images should be classified as.
wow thanks a lot for this easy and simple explanation . about the step 5 this screen shot explains exactly what should be done.. you can tell me if i am right or not (as i am not good in mat lab ) .. the three highest is sort of array and i have to loop on it using if conditions for each image of the already saved ones ? could you please correct me if i am wrong ?
I'm not sure that algorithm would work, but you're welcome to try it anyway. You'd of course need all the 16 images by themselves, and they should be the same size. Use imresize() or imcrop() if they're not.
raymon hani
raymon hani 2016년 12월 11일
편집: raymon hani 2016년 12월 11일
oh that is a complete motivation thanks a lot :D but please enlighten me if there are better algorithms to look at .. as i told you i am very bad with mat lab and i am not sure how to manipulate the three highest variable :D
I'm not a handwriting expert. You can find all the algorithms here: http://www.visionbib.com/bibliography/contentschar.html#OCR,%20Document%20Analysis%20and%20Character%20Recognition%20Systems Look in the handwriting section.
you are a great expert for me :D i searched even more and found this code ... thank to you i understood the part of the steps you explained to me but i don't understand the vector= zeros(3,15) and result(j,i) = result(j,i)= sqrt((testImageFeature(1)-theVector(j,i))^2+(testImageFeature(2)-theVector(j,i))^2+(testImageFeature(3)-theVector(j,i))^2);
in general the next steps to what you explained, could you please simplify it ? ( i am very sorry for lots of question but i would appreciate helping me pass this project :D
images{1}=database_1;
images{2}=database_2;
images{3}=database_3;
images{4}=database_4;
images{5}=database_5;
images{6}=database_6;
images{7}=database_7;
images{8}=database_8;
images{9}=database_9;
images{10}=database_10;
images{11}=database_11;
images{12}=database_12;
images{13}=database_13;
images{14}=database_14;
images{15}=database_15;
theVector = zeros(3,15);
for i = 1:15
myImg = rgb2gray(images{i});
FourierForImg = fft2(double(myImg));
imagesFeatures = abs(FourierForImg(:));
imagesFeatures = sort(imagesFeatures,'descend');
threeFeature= imagesFeatures(1:3);
for j = 1:3
theVector(j,i)= threeFeature(j);
end
end
result = zeros(3,15);
for i = 1:15
for j = 1:3
result(j,i)= sqrt((testImageFeature(1)-theVector(j,i))^2+(testImageFeature(2)-theVector(j,i))^2+(testImageFeature(3)-theVector(j,i))^2);
end
end
nearestCluster = zeros(1,15);
for i=1:15
for j = 1:3
test(j) = result(j,i);
end
theNearest(i) = min(test);
end
theClass = min(theNearest);
[distance,index] = min(theNearest);
subplot(211);imshow(TestImage );subplot(212);imshow(images{index});
Thank you so much for your help i swear i couldn't understand what i am doing without your help ... i hope you are reading this :) best wishes Mr.Image Analyst
Maybe you could use kmeans(), in the Statistics and Machine Learning Toolbox, with a k of 5 since you know there are 5 characters so with the 15 observations there should be 5 clusters.
Salma Yassin
Salma Yassin 2017년 12월 8일
편집: Salma Yassin 2017년 12월 8일
Hello Raymon, I have the same assignment :D, I was able to get the three highest magnitudes for all the images but I am not sure on how to classify the test image to one of the classes. Can you help me out?
Hello Salma :D After getting the three highest magnitude, you should be able to loop over all the images you already have. These are called the dataset. Next, create a matrix 3x15 if you have 15 dataset image like in my assignment :D Now you have all the magnitudes of the already given images and the inserted or tested image in another 3x1 matrix. Now the process of classification can be both complex or easy ... If you attended the data mining course or have idea about machine learning techniques you will find that the classification has a lot of methods . The easiest could be K-nearest neighbour or more complex like neural networks or support vector machines. However if this is an image processing assignment you don't wanna put so much effort in classification rather than image enhancement and focusing on Fourier transform which you already did as you said ... So using k-nearest neighbor will be an excellent usage for a small data set , however notice that the more the data set gets bigger the more you will need a more accurate technique like neural networks. Anyhow, i am sure you will do some researches about k nearest neighbor but goes like follows, you loop over all the images already given as a dataset, and the newly introduced image ( the one you want to classify ) .probably you will use nested loop. And use the euclidian equation to find out the distance between the value of the indexed value of the dataset and the new image... It will go something like this
For(i=0, i<15,i++){ For(y=0 ,i<3,i++) This will loop over the three highest magnitudes of eah image from the 15 image pre given
Next Create a matrix to assign each distances to it ...
Newmatrix[i][y]= (dataset[0][0]-classifiedimage[0][0]) + etc.....
You should substract every highest magnitudes of the classified image from the the already given pictures So it goes like (mag1-mag1)+(mag2-mag2)+(mag3-mag3)
The lowest result should be the closet distance .. this is the one you want ...
However if you have any question feel free to ask .. or if you have any communication way .. i can send you my assignment :D
Sorry for the long answer but i hope it is useful
Erick Smith
Erick Smith 2017년 12월 9일
편집: Erick Smith 2017년 12월 9일
hi there, i'am having the same assignment too :D. i believe i have finished working on it. i would appreciate if you could send me a copy of your assignment just to check my work. my gmail is ( ericksmith714@gmail.com ) thanks in advance.
Salma Yassin
Salma Yassin 2017년 12월 9일
편집: Salma Yassin 2017년 12월 10일
Thank you so much for your help :D, I thought I wont be able understand this assignment but I did thanks to you guys, thank you so much. Best wishes :D
Sam Alex
Sam Alex 2017년 12월 9일
Hello Raymon, i have an assignment similar to your's, and i cant get the nearest neighbor to assign to its closest class. Could you tell me how to implement it. I would be too much thankful if you could send me your assignment to reference from it the steps of implementation to my email samalexcs1993@gmail.com. Thanks in Advance,
seif amr
seif amr 2017년 12월 9일
i have the same assignment can you send your assignment to take it as a refrence via e mail seif133649@bue.edu.eg thanks

댓글을 달려면 로그인하십시오.

추가 답변 (3개)

Sam Alex
Sam Alex 2017년 12월 9일

0 개 추천

Hello Raymon, i have an assignment similar to your's, and i cant get the nearest neighbor to assign to its closest class. Could you tell me how to implement it. I would be too much thankful if you could send me your assignment to reference from it the steps of implementation to my email samalexcs1993@gmail.com. Thanks in Advance,
Image Analyst
Image Analyst 2017년 12월 10일

0 개 추천

The DC value is the value at element (1,1). Get this BEFORE you call fftshift, because fftshift will move the DC location to the center of the image.
To get the "three highest spectrum magnitudes" simply sort and pick off the first 3:
fftMagnitude = abs(fftA);
sortedMags = sort(fftMagnitude(:), 'descend');
threeHighest = sortedMags(1:3);
Note, fftMagnitude(:) turns the 2-D array into a column vector. Also note that in most "normal" signals, the 3 highest signals will be the DC signal and the to elements immediately on either side of the DC element. For them not to be there, you'd need to have some kind of periodic signal in the spatial domain that would give really big spikes in the Fourier (spectral) domain. If the signal is not periodic, like just some general snapshot image you snapped, then it will be highest at DC and fall away sharply as you move away from DC.
Greg Heath
Greg Heath 2017년 12월 10일

0 개 추천

I learned (decades ago !!!), that explictly removing the mean value before using the FFT eliminates a multitude of problems when trying to use and/or understand the transform.
Reason? The fft of the mean value contains sidelobes that contaminate the spectrum at nonzero frequencies.
Bottom line:
ALWAYS REMOVE THE DC LEVEL BEFORE TRANSFORMING!!!
Hope this helps
Thank you for formally accepting my answer
Greg

질문:

2016년 12월 10일

답변:

2017년 12월 10일

Community Treasure Hunt

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

Start Hunting!

Translated by