From: Jan Simon on
Dear Fiza,

When I'm reading a JPEG I get an UINT8 vector already. So actually there is no need to cast.

Im = imread('img2.jpg');
x = java.security.MessageDigest.getInstance('MD5');
x.update(typecast(Im(:), 'uint8')); % Or simply: x.update(Im(:));
Key = typecast(x.digest, 'uint8'); % INT8 -> UINT8

There is no need to DEC2BIN, TYPECAST, repeated SIZE, explicite casting to UINT8, if you just want the MD5 of the contents of the image.
I'm not sure if this works for grayscale JPGs also - perhaps you need to insert a IND2RGB call then.

If this works for you, I'm wondering, why this needed 29 posts.

Jan
From: fiza khalid on
"Jan Simon" <matlab.THIS_YEAR(a)nMINUSsimon.de> wrote in message <i0l5hg$1qc$1(a)fred.mathworks.com>...
> Dear Fiza,
>
> When I'm reading a JPEG I get an UINT8 vector already. So actually there is no need to cast.
>
> Im = imread('img2.jpg');
> x = java.security.MessageDigest.getInstance('MD5');
> x.update(typecast(Im(:), 'uint8')); % Or simply: x.update(Im(:));
> Key = typecast(x.digest, 'uint8'); % INT8 -> UINT8
>
> There is no need to DEC2BIN, TYPECAST, repeated SIZE, explicite casting to UINT8, if you just want the MD5 of the contents of the image.
> I'm not sure if this works for grayscale JPGs also - perhaps you need to insert a IND2RGB call then.
>
> If this works for you, I'm wondering, why this needed 29 posts.
>
> Jan
>>thnx jan its working now but tell me last thing that how do i confirm that it is giving correct hash of an image or not.
From: Steven Lord on

"fiza khalid" <princess.2050(a)hotmail.com> wrote in message
news:i0l808$dhu$1(a)fred.mathworks.com...
> "Jan Simon" <matlab.THIS_YEAR(a)nMINUSsimon.de> wrote in message
> <i0l5hg$1qc$1(a)fred.mathworks.com>...
>> Dear Fiza,
>>
>> When I'm reading a JPEG I get an UINT8 vector already. So actually there
>> is no need to cast.
>>
>> Im = imread('img2.jpg');
>> x = java.security.MessageDigest.getInstance('MD5');
>> x.update(typecast(Im(:), 'uint8')); % Or simply: x.update(Im(:));
>> Key = typecast(x.digest, 'uint8'); % INT8 -> UINT8
>>
>> There is no need to DEC2BIN, TYPECAST, repeated SIZE, explicite casting
>> to UINT8, if you just want the MD5 of the contents of the image.
>> I'm not sure if this works for grayscale JPGs also - perhaps you need to
>> insert a IND2RGB call then.
>>
>> If this works for you, I'm wondering, why this needed 29 posts.
>>
>> Jan
>>>thnx jan its working now but tell me last thing that how do i confirm
>>>that it is giving correct hash of an image or not.

1) Generate test cases for which you know the correct hash.
2) Generate the hashes for the test cases using your code.
3) Compare the known hashes to your code's hashes.
4) Fix bugs exposed by step 3 and return to step 2.
5) If you're satisfied that your code is correct, end.
6) Return to step 1 to generate additional test cases.

--
Steve Lord
slord(a)mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
To contact Technical Support use the Contact Us link on
http://www.mathworks.com


From: Jan Simon on
Dear Fiza,

>its working now but tell me last thing that how do i confirm that it is giving correct hash of an image or not.

How would or could you define "correct" for a hash??
You can trust the Java libs, because they are tested millions of times. So any other computer, which uses an equivalent lib to calculate an MD5 will reply the same hash for the contents of the JPEG.

Nevertheless, you could calculate the hash for the complete file also, such that the header and comment is included.
If you define exactly, what you use as input to the MD5, the hash is "correct" already.

What do you want to achieve with building a hash for a picture?
If you formulate your demands exactly, it will take less than 29 posts to assist you.

Kind regards, Jan
From: Walter Roberson on
fiza khalid wrote:

> Error in ==> hash2 at 70
> inp=typecast(inp,'uint8');
> plz let me know how to remove that error.

Hard to believe you are still working on this a week or more later.

inp = typecast(inp(:),'uint8');