DCT code for image hash

9 ビュー (過去 30 日間)
Sundara Krishnan N
Sundara Krishnan N 2018 年 2 月 4 日
回答済み: Abhishek Ballaney 2018 年 2 月 5 日
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

回答 (1 件)

Abhishek Ballaney
Abhishek Ballaney 2018 年 2 月 5 日
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!

Translated by