Function iasubm

namespace:morph
page:iasubm

Synopse

Subtraction of two images, with saturation.

  • y = iasubm(f1, f2)
    • y: Image
    • f1: Image
    • f2: Image Or constant.
01. from numpy import *
02. 
03. def iasubm(f1, f2):
04.     from ialimits import ialimits
05. 
06.     if type(f2) is array:
07.         assert f1.dtype == f2.dtype, 'Cannot have different datatypes:'
08.     k1,k2 = ialimits(f1)
09.     y = clip(f1.astype(int32)-f2, k1, k2)
10.     y = y.astype(f1.dtype)
11.     return y

Description

iasubm creates the image y by pixelwise subtraction of the image f2 from the image f1. When the subtraction of the values of two pixels is negative, 0 is taken as the result of the subtraction. When f1 and f2 are binary images, y represents the set subtraction of f2 from f1.

Examples

Example 1

1. from ia870 import iasubm
2. 
3. 
4. f = uint8([255,   255,    0,   10,   20,   10,    0,   255,  255])
5. g = uint8([10,     20,   30,   40,   50,   40,   30,    20,    10])
6. print iasubm(f, g)
7. print iasubm(f, 100)
8. #print iasubm(100, f)
[245 235   0   0   0   0   0 235 245]
[155 155   0   0   0   0   0 155 155]

Example 2

1. a = mmreadgray('boxdrill-C.tif')
2. b = mmreadgray('boxdrill-B.tif')
3. c = iasubm(a,b)
4. mmshow(a)
5. mmshow(b)
6. mmshow(c)

Equation