Esempio n. 1
0
def main(image, prototype, center, rhoList, sigma0,  alpha, rotationInvariance):
	proto = np.asarray(prototype, dtype=np.float64)
	subject = 255 - np.asarray(image, dtype=np.float64)[:,:,1]
	subject = subject/255

	cosfire_symm = c.COSFIRE(c.CircleStrategy, c.DoGFilter, (2.4, 1), prototype=proto, center=(cx,cy), rhoList=range(0,9,2), sigma0=3,  alpha=0.7, rotationInvariance = np.arange(12)/12*np.pi).fit()
	result_symm = cosfire_symm.transform(subject)

	Image.fromarray(c.rescaleImage(cosfire_symm.strategy.protoStack.stack[0].image, 0, 255).astype(np.uint8)).save('output/filtered_prototype_symm.png')
	result = c.rescaleImage(result_symm, 0, 255)
	return result
Esempio n. 2
0
def main(image, prototype, center, sigma, rhoList, sigma0,  alpha, rotationInvariance):
	proto = np.asarray(prototype, dtype=np.float64)
	# print('>>>>>>>>!',prototype[100,100])
	# print(image, prototype, center, sigma, rhoList, sigma0,  alpha, rotationInvariance)
	subject = 255 - np.asarray(image, dtype=np.float64)
	subject = subject/255
	cosfire_symm = c.COSFIRE(c.CircleStrategy(c.DoGFilter, (sigma, 1), prototype=prototype, center=center, rhoList=rhoList, sigma0=sigma0,  alpha=alpha, rotationInvariance = rotationInvariance)).fit()
	result_symm = cosfire_symm.transform(subject)
	result = c.rescaleImage(result_symm, 0, 255)
	return result
Esempio n. 3
0
		c.CircleStrategy, c.DoGFilter, (1.8, 1), prototype=proto_symm, center=(cx,cy), rhoList=range(0,23,2), sigma0=2,  alpha=0.1,
		rotationInvariance = np.arange(24)/12*np.pi
	   ).fit()
# Make asymmetrical
asymmTuples = []
for tupl in cosfire_asymm.strategy.tuples:
	if tupl[1] <= np.pi:
		asymmTuples.append(tupl)
cosfire_asymm.strategy.tuples = asymmTuples
result_asymm = cosfire_asymm.transform(subject)

# filtered prototypes
#filtered_prototype_symm = c.rescaleImage(cosfire_symm.strategy.protoStack.stack[0].image, 0, 255).astype(np.uint8)
#filtered_prototype_asymm = c.rescaleImage(cosfire_asymm.strategy.protoStack.stack[0].image, 0, 255).astype(np.uint8)

# Add results from symmetrical and asymmetrical operators
result = result_symm + result_asymm

print('[TEST 4] rot1 the same:', compareMat(response_rot1,result_symm))
print('[TEST 5] rot2 the same:', compareMat(response_rot2,result_asymm))
print('[TEST 6] result sum the same:', compareMat(response_imageSum,result))

# Stretching and binarization
result_symm = c.rescaleImage(result_symm, 0, 255)
result_asymm = c.rescaleImage(result_asymm, 0, 255)
result = np.multiply(result, mask)
result = c.rescaleImage(result, 0, 255)
binaryResult = np.where(result > 37, 1, 0)
print('[TEST 7] response the same:', compareMat(response_rescaled,result))
print('[TEST 8] binary the same:', compareMat(output_segmented,binaryResult))
Esempio n. 4
0
# Store timing
global_timings.append(
    ("Creating the asymmetrical filter, fitting it with the prototype",
     time.time() - t3))
t4 = time.time()  # Time point

result_asymm = cosfire_asymm.transform(subject)

# Store timing
global_timings.append(("Transforming the subject with the asymmetrical filter",
                       time.time() - t4))

# Save filtered prototypes for reference
Image.fromarray(
    c.rescaleImage(cosfire_symm.strategy.protoStack.stack[0].image, 0,
                   255).astype(
                       np.uint8)).save('output/filtered_prototype_symm.png')
Image.fromarray(
    c.rescaleImage(cosfire_asymm.strategy.protoStack.stack[0].image, 0,
                   255).astype(
                       np.uint8)).save('output/filtered_prototype_asymm.png')

t5 = time.time()  # Time point

# Add results from symmetrical and asymmetrical operators
result = result_symm + result_asymm

# Stretching and binarization
result_symm = c.rescaleImage(result_symm, 0, 255)
result_asymm = c.rescaleImage(result_asymm, 0, 255)
#result = np.multiply(result, mask)
Esempio n. 5
0
import numpy as np
from PIL import Image
import cosfire as c

if (len(sys.argv) < 3):
    if (len(sys.argv) == 2):
        name = sys.argv[1]
        img = np.asarray(Image.open(name).convert('L'), dtype=np.float64)
        print(img)
        print(np.max(img))
        print(np.min(img))
        sys.exit()
    else:
        sys.exit("Give two image paths")

name1 = sys.argv[1]
name2 = sys.argv[2]

img1 = np.asarray(Image.open(name1).convert('L'), dtype=np.float64)
img2 = np.asarray(Image.open(name2).convert('L'), dtype=np.float64)

result = img1 - img2

img = Image.fromarray(c.rescaleImage(result, 0, 255).astype(np.uint8))
img.save('comparison.png')

print(result)
print(np.max(result))
print(np.min(result))
print(np.sum(result))