Image authentication using color information

I am using attached script for splitting the image into 21 blocks (for Red, Green and Blue channels) and then compare each block pixel by pixel.
However, I want to do some changes as below:
1) How can I divide the image automatically into n number of equal blocks ( so I will just have to say 10 and it will divide the image into 10 equal size blocks).
2) I used isequal() function for comparison two blocks. How can I get the distance between two blocks. (Like Euclidean distance or something)
3) How to compare RGB histogram for each block. (Here I think it is possible to only compare the Y axis as X axis of the histogram will be 0 to 255 for all the blocks.) I know how to generate histogram but I dont know how to use that information for the comparison.
4) How can I keep some threshold e.g after comparison if all the blocks are matching > 98% then it is a true image OTW false image detected.
Thank you in advance.

11 件のコメント

Guillaume
Guillaume 2018 年 12 月 3 日
You've told us what you want to do but you haven't asked any actual question, so it's unclear what help you need.
"As isequal() was giving error for A x B x 3 block. It can only compare A x B type blocks."
isequal does not care one bit about the number of dimensions of the input. It will work just as well with an AxBx3 input as an AxB input or even an AxBxCxDxEx... input. If the two inputs don't have the same number of dimensions, isequal job is easy, the answer is false.
Devarshi Patel
Devarshi Patel 2018 年 12 月 3 日
Please refer the question now. Sorry for the confusion before.
And sorry there wasn't any error for A x B x 3 i tried again.
Regards,
Devarshi
Guillaume
Guillaume 2018 年 12 月 3 日
How can I divide the image automatically into n number of equal blocks ( so I will just have to say 10 and it will divide the image into 10 equal size blocks)
Dividing an image into a non-prime number of blocks is easy. However, if the image size is not a multiple of the number of blocks,it's going to be difficult to divide it into blocks all the same size.
Also, if it is to be divided into 10 blocks, is it 5x2 or 2x5 blocks?
Devarshi Patel
Devarshi Patel 2018 年 12 月 3 日
編集済み: Devarshi Patel 2018 年 12 月 3 日
I can keep the image size fixed like 200 x 200 or 200 x 250 ( square or rectangle). and I want to keep the number of rows and colum same like 3x3 or 4x4. (in case of rectangle 2 x 5).
I also changed the 2nd point of the question.
Image Analyst
Image Analyst 2018 年 12 月 6 日
Why do you want to "compare" images in this way? What's the use case? Is it to test quality of compression/restoration? Forensics? Forgeries? What? If we knew what it was for we could point to the right place to find the right algorithms for that purpose.
Devarshi Patel
Devarshi Patel 2018 年 12 月 6 日
編集済み: Devarshi Patel 2018 年 12 月 7 日
I want to do authentication based on color information of the image (RGB histogram). two images can have same histogram that is the reason behind dividing it into sub block and then do the comparison between each block, so it can give more reliable results. Think of it as a bank card with the image on it for the authentication If you try to us counterfeit card (with slightly different image) it will not authenticate you.
Later on, I want to add the feature detection and comparison to this. So, combination of color information as well as features.
Devarshi Patel
Devarshi Patel 2018 年 12 月 7 日
I used code provided by Guillaume. How can I do histogram comparision for each block insted of comparing entire block?
I tried explaining in the attache figure. In the figure there is one dataset. in my case there will be 3 data set (R, G and B).
clear
clc
%inputs:
% img: an image (2D or 3D numeric array)
% M, N: the number of blocks along the rows, columns respectively
%output:
% block: a M x N cell array of 2D or 3D numeric arrays
img1 = imread('w.png');
M = 3;
N = 7;
blocks1 = mat2cell(img1, ones(1, M) * size(img1, 1) / M, ones(1, N) * size(img1, 2) / N, size(img1, 3)); %will error if M and N are not divisors of H and W
% second image
img2 = imread('b.png');
M1 = 3;
N1 = 7;
blocks2 = mat2cell(img2, ones(1, M1) * size(img2, 1) / M1, ones(1, N1) * size(img2, 2) / N1, size(img2, 3)); %will error if M and N are not divisors of H and W
%inputs:
% blocks1: blocks of 1st image. M x N cell array of 2D or 3D numeric arrays
% blocks2: blocks of 2nd image. Same size as blocks1
%outputs:
% comparison: a M X N double array of euclidean distance between each matching block.
comparison = cellfun(@(b1, b2) sqrt(sum((b1(:) - b2(:)) .^2)), blocks1, blocks2)
Devarshi Patel
Devarshi Patel 2018 年 12 月 10 日
Can you help me with writing the code using attached paper information. I can understand it mathematically but I dont know how to write it in matlab script.
Guillaume
Guillaume 2018 年 12 月 10 日
1) The paper you've attached is copyrighted and not open access. Can you please remove the attachment?
Devarshi Patel
Devarshi Patel 2018 年 12 月 10 日
I removed the paper. Can you please help me with modifying the code that you suggested for histogram comparison? As I tried to get histogram of the sub image blocks but couldn't do it. Please help me with this.
Devarshi Patel
Devarshi Patel 2018 年 12 月 10 日
編集済み: Devarshi Patel 2018 年 12 月 10 日
If you dont have enough time can you at least show me how to get the histogram of each block in blocks 1 and blocks 2 generated by:
clear
clc
%inputs:
% img: an image (2D or 3D numeric array)
% M, N: the number of blocks along the rows, columns respectively
%output:
% block: a M x N cell array of 2D or 3D numeric arrays
img1 = imread('w.png');
M = 3;
N = 7;
blocks1 = mat2cell(img1, ones(1, M) * size(img1, 1) / M, ones(1, N) * size(img1, 2) / N, size(img1, 3)); %will error if M and N are not divisors of H and W
% second image
img2 = imread('b.png');
M1 = 3;
N1 = 7;
blocks2 = mat2cell(img2, ones(1, M1) * size(img2, 1) / M1, ones(1, N1) * size(img2, 2) / N1, size(img2, 3)); %will error if M and N are not divisors of H and W
%inputs:
% blocks1: blocks of 1st image. M x N cell array of 2D or 3D numeric arrays
% blocks2: blocks of 2nd image. Same size as blocks1
%outputs:
% comparison: a M X N double array of euclidean distance between each matching block.
comparison = cellfun(@(b1, b2) sqrt(sum((b1(:) - b2(:)) .^2)), blocks1, blocks2)
This will be very helpful Please help me with this.

サインインしてコメントする。

 採用された回答

Guillaume
Guillaume 2018 年 12 月 4 日

0 投票

1. Dividing an image of size HxW into MxN blocks where M and N are divisors of H and W respectively:
%inputs:
% img: an image (2D or 3D numeric array)
% M, N: the number of blocks along the rows, columns respectively
%output:
% block: a M x N cell array of 2D or 3D numeric arrays
blocks = mat2cell(img, ones(1, M) * size(img, 1) / M, ones(1, N) * size(img, 2) / N, size(img, 3)); %will error if M and N are not divisors of H and W
2. It seems to me that you haven't defined your comparison metric. You probably need to do some research on what it should be. Once you've defined that, it's easy to perform the comparison. Here, I'm using the square root of the sum of the square of the differences between corresponding pixels of each block. I have no idea if it is a good metric, as it's not my field:
%inputs:
% blocks1: blocks of 1st image. M x N cell array of 2D or 3D numeric arrays
% blocks2: blocks of 2nd image. Same size as blocks1
%outputs:
% comparison: a M X N double array of euclidean distance between each matching block.
comparison = cellfun(@b1, b2) sqrt(sum((b1(:) - b2(:)) .^2)), blocks1, blocks2)
3. Again, making the comparison is trivial but you need to define a metric first.

11 件のコメント

Devarshi Patel
Devarshi Patel 2018 年 12 月 4 日
編集済み: Devarshi Patel 2018 年 12 月 4 日
I tried using your script (Please find attached file Split_comparision) but there is some error in comparison part.
2) I want to do use Euclidean distance and Dynamic Time wrapping (to compare both results). Here can I get number value for the comparison like if it is matching 100% then it will give Euclidian distance of 0 and if it is matching 0% then it will give max number like 100.
3) I am uploading another image (flowchart) so you can have clear idea. (This flow chart is for the comparison using histogram)
Guillaume
Guillaume 2018 年 12 月 4 日
I'm sorry but I don't have the time to test your code. If you get an error, give the exact, full error message you get, rather than leaving it up to me to find out.
Your flowchart just repeat what you have stated. Missing from your flow chart is what the comparison algorithm is. I still have no idea what your metric is.
Devarshi Patel
Devarshi Patel 2018 年 12 月 4 日
編集済み: Devarshi Patel 2018 年 12 月 4 日
I tried using your script (Please find attached file Split_comparision) but there is some error in comparison part.
Sorry I didn't include the error before
Error:
Error: File: Split_comparison.m Line: 22 Column: 31
Invalid expression. Check for missing multiplication operator, missing or unbalanced delimiters, or other syntax error. To construct matrices, use brackets instead of parentheses.
This is coming for ''comparison = cellfun(@b1, b2) sqrt(sum((b1(:) - b2(:)) .^2)), blocks1, blocks2)''
2) I want to do use Euclidean distance and Dynamic Time wrapping (to compare both results). Here can I get number value for the comparison like if it is matching 100% then it will give Euclidian distance of 0 and if it is matching 0% then it will give max number like 100.
3) I am uploading another image (flowchart) so you can have clear idea. (This flow chart is for the comparison using histogram)
Guillaume
Guillaume 2018 年 12 月 4 日
Ok, it was missing a bracket in the expression:
comparison = cellfun(@(b1, b2) sqrt(sum((b1(:) - b2(:)) .^2)), blocks1, blocks2)
Devarshi Patel
Devarshi Patel 2018 年 12 月 5 日
Is there any way to get just a number instead of the matrix for the comparison result?
Also how to do the comparison if we are using RGB histogram for each image block comparison?
Guillaume
Guillaume 2018 年 12 月 5 日
編集済み: Guillaume 2018 年 12 月 5 日
"Is there any way to get just a number instead of the matrix for the comparison result?"
Yes, as soon as you've defined exactly how that single number is to be calculated, as I keep asking.
Devarshi Patel
Devarshi Patel 2018 年 12 月 5 日
I dont know the best way but can we convert the final matrix in to one number as explained in attached fig.?
Guillaume
Guillaume 2018 年 12 月 5 日
Seems like a very poor metric to me, particularly, the pointless squaring, but sure:
finalvalue = sum(comparison(:)) ^ 2;
if on R2018b,
finalvalue = sum(comparison, 'all') ^ 2;
Devarshi Patel
Devarshi Patel 2018 年 12 月 5 日
編集済み: Devarshi Patel 2018 年 12 月 5 日
If you have any suggestions please let me know as this is also new for me
Guillaume
Guillaume 2018 年 12 月 6 日
As I said it's not my domain. However, I'm sure you can find plenty of reliable methods in the plethora of papers that have been written on the subject.
Devarshi Patel
Devarshi Patel 2018 年 12 月 6 日
I will go through some papers for that.
Another thing I am confuse about is how is euclidean distance formula "comparison = cellfun(@(b1, b2) sqrt(sum((b1(:) - b2(:)) .^2)), blocks1, blocks2)" is working in my case as each pixel has 3 value (R,G and B) specifically how it is taking the diffrence and coming up with the single number. Maybe it is sill question but I am not understanding it. I tried going through the cellfun discription. Any explanation will be appreciated.

サインインしてコメントする。

その他の回答 (2 件)

Image Analyst
Image Analyst 2018 年 12 月 7 日

0 投票

Maybe you should just try ro register the images with imregister() and then use immse() and ssim().
Or you could also use Hu's moments
Or any of the feature matching things in the Computer Vision System Toolbox.

3 件のコメント

Devarshi Patel
Devarshi Patel 2018 年 12 月 7 日
None of the suggested method uses color information for the comparison. As my images will be very similar structure wise but different color. Please find attached files for the example. Both images have same structural features but different colors.
Image Analyst
Image Analyst 2018 年 12 月 7 日
There are so very many things that could possibly be measured. For one, you could just compute the RGB histograms of each image. Better, why don't you look up forgery or forensics in VisionBibliography and you'll find lots of algorithms. Pick one or two and code them up:
Devarshi Patel
Devarshi Patel 2018 年 12 月 7 日
I tried looking into few papers but none of them are helpful for writing a MATLAB code (may be because I am new and know very little coding). I will investigate it more. Thank you for your suggestion.If any particular code (which considers colors as well as structural features for image comparison) comes to your mind please let me know as database have thousands of papers.

サインインしてコメントする。

Devarshi Patel
Devarshi Patel 2018 年 12 月 19 日

0 投票

Hi Guillaume & Image Analyst,
Thank you for your answers so far I have just last question after that I will Accept the answer. Attached images are same images and taken in same condition but still when you compare 2 images it shows larger distance. Can you give me any suggestions how to solve this ? Is there any way of preprocessing to match the images? like thresholding or removing the noise or something similar

製品

リリース

R2018b

質問済み:

2018 年 12 月 3 日

回答済み:

2018 年 12 月 19 日

Community Treasure Hunt

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

Start Hunting!

Translated by