how can i find the number of the overlapped white pixels between 2 black and white images?

Hi all
i have 2D images (BW), i performed transformation on one of them ,while keeping one without any changes , after that i need to find the number of the overlapped white pixels between imag1 and transformed imag2 ? how can i do this in matlab ?
please , i need simple illustration .
regards

回答 (1 件)

Sven
Sven 2012 年 2 月 15 日
Im1 = rand(50,50)>0.2; % your first image
Im2 = rand(50,50)>0.6; % your transformed image
overlapIm = Im1 & Im2;
numSharedWhitePixels = nnz(overlapIm);
Is that what you were looking for?

5 件のコメント

mmm ssss
mmm ssss 2012 年 2 月 15 日
why you use these values 50 ,0.2,0.6?
also i need to this automatically because , i have 20 images so, i need to perform many comparisons.thnx
Ashish Uthama
Ashish Uthama 2012 年 2 月 16 日
Those are examples Sven used to convey the idea of using '& and nnz. Think of Im1 as the 'keeping one without any changes' and Im2 as the 'performed transformation on one of them' from your description.
mmm ssss
mmm ssss 2012 年 2 月 16 日
@Ashisha
thanks alot for your perfect illustration , but if IM1 & IM2 are not of the same matrix dimensions ,how can i make them with the same dimension to perform '& operator'.
Image Analyst
Image Analyst 2012 年 2 月 16 日
If the images are not of the same size, you need to rethink what you're attempting to do. Why did it change size? Just what kind of transform are you doing? Maybe you can resize one of the images to match the other.
mmm ssss
mmm ssss 2012 年 2 月 17 日
@image analyst .for example
i wrote
xform=[cos(-50) sin(-50) 0 ;-sin(-50) cos(-50) 0;-50 50 1];
t_form_rotate_translate=maketform('affine',xform);
cb_trans=imtransform(p2,t_form_rotate_translate);
the size of p2 was 174*320,while the size of cb_trans is 252*355?
but i need to ask you is the translation and rotation will change the size of P2 when they implemented on it or there is a problem in my transformation ?how can i know this?
And if these transformations change the size, can i simply resized the op to be similar to ip to performing AND operator or not.?please i need illustration .

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

質問済み:

2012 年 2 月 15 日

編集済み:

dpb
2013 年 10 月 15 日

Community Treasure Hunt

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

Start Hunting!

Translated by