DCT code for image hash
Show older comments
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
on 5 Feb 2018
1 vote
https://www.mathworks.com/help/images/ref/dct2.html
Categories
Find more on Image Transforms 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!