DCT code for image hash

4 views (last 30 days)
Sundara Krishnan N
Sundara Krishnan N on 4 Feb 2018
I am working on a project to assign fingerprint to images using pHash. I happened to get the following code from StackOverflow:
% read image
I = imread('cameraman.tif');
% cosine transform and reduction
d = dct2(I);
d = d(1:8,1:8);
% compute average
a = mean(mean(d));
% set bits, here unclear whether > or >= shall be used
b = d > a;
% maybe convert to string:
string = num2str(b(:)');
When I run the code, I get the following errors, all of which are associated with built-in functions:
Matrix dimensions must agree.
Error in dct (line 76)
b = W .* fft(y);
Error in dct2 (line 50)
b = dct(dct(arg1).').';
Error in flipimage (line 4)
d = dct2(I);
Please help me to resolve these errors

Answers (1)

Abhishek Ballaney
Abhishek Ballaney on 5 Feb 2018
https://www.mathworks.com/help/images/ref/dct2.html

Community Treasure Hunt

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

Start Hunting!