Function iacmp

namespace:morph
page:iacmp

Synopse

Compare two images pixelwisely.

  • y = iacmp(f1, oper, f2, oper1=NULL, f3=NULL)
    • y: Image
    • f1: Image
    • oper: String relationship from: '==', '~=', '<','<=', '>', '>='.
    • f2: Image
    • oper1: String relationship from: '==', '~=', '<','<=', '>', '>='.
    • f3: Image
01. from numpy import *
02. 
03. def iacmp(f1, oper, f2, oper1=None, f3=None):
04.     from iaintersec import iaintersec
05.     from iabinary import iabinary
06. 
07. 
08.     if   oper == '==':    y = (f1==f2)
09.     elif oper == '~=':    y = (f1!=f2)
10.     elif oper == '<=':    y = (f1<=f2)
11.     elif oper == '>=':    y = (f1>=f2)
12.     elif oper == '>':     y = (f1> f2)
13.     elif oper == '<':     y = (f1< f2)
14.     else:
15.         assert 0, 'oper must be one of: ==, ~=, >, >=, <, <=, it was:'+oper
16.     if oper1 != None:
17.         if   oper1 == '==':     y = iaintersec(y, f2==f3)
18.         elif oper1 == '~=':     y = iaintersec(y, f2!=f3)
19.         elif oper1 == '<=':     y = iaintersec(y, f2<=f3)
20.         elif oper1 == '>=':     y = iaintersec(y, f2>=f3)
21.         elif oper1 == '>':      y = iaintersec(y, f2> f3)
22.         elif oper1 == '<':      y = iaintersec(y, f2< f3)
23.         else:
24.             assert 0, 'oper1 must be one of: ==, ~=, >, >=, <, <=, it was:'+oper1
25. 
26.     y = iabinary(y)
27. 
28. 
29.     return y

Description

Apply the relation oper to each pixel of images f1 and f2, the result is a binary image with the same size. Optionally, it is possible to make the comparison among three image. It is possible to use a constant value in place of any image, in this case the constant is treated as an image of the same size as the others with all pixels with the value of the constant.

Examples

Example 1

1. from ia870 import iacmp
2. 
3. 
4. print iacmp(uint8([1, 2, 3]),'<', uint8(2))
5. print iacmp(uint8([1, 2, 3]),'<', uint8([0, 2, 4]))
6. print iacmp(uint8([1, 2, 3]),'==', uint8([1, 1, 3]))
[ True False False]
[False False  True]
[ True False  True]

Example 2

1. f=mmreadgray('keyb.tif')
2. fbin=iacmp(uint8(10), '<', f, '<', uint8(50))
3. mmshow(f)
4. mmshow(fbin)