Beispiel #1
0
from readpgm import read_pgm, list_to_2D_list, copy
from momentFunction import pqmoment, pqN, pqHu
from etc_function import createHistogram
filename = "./image/1./scaled_shapes.pgm"
converted_img = []
mattrix_img = []
col = 0
row = 0

converted_img, col, row = read_pgm(filename, col, row)
mattrix_img = list_to_2D_list(converted_img, mattrix_img, col, row)

object_dict = {}
count = 0

histogram = createHistogram(converted_img)
# count object
for key in histogram:
    if histogram[key] > 1500 and key != 255:
        object_dict[key] = histogram.get(key)
        count = count + 1

print("Histogram of image :")
print(histogram)
print("Number of Object : " + str(count))
print("Gray level of each object")
print(object_dict)

maskesOb_img = copy(mattrix_img)

for key in object_dict:
from readpgm import read_pgm, list_to_2D_list, copy
from writepgm import writepgm
from etc_function import createHistogram
filename = "./image/2./Cameraman.pgm"
# filename = "./image/2./SEM256_256.pgm"

converted_img = []
mattrix_img = []
col = 0
row = 0

converted_img, col, row = read_pgm(filename, col, row)
mattrix_img = list_to_2D_list(converted_img, mattrix_img, col, row)
histogram_old = createHistogram(converted_img)
current_D = []
miss_frequency = []
miss_update = {}
for i in range(256):  # find miss colour
    if i not in histogram_old:
        miss_frequency.append(i)
# complete with colore frequenct = 0
miss_update = {i: 0 for i in miss_frequency}
for key in miss_update:
    histogram_old.update({key: miss_update[key]})

histogram_old = {
    key: histogram_old[key]
    for key in sorted(histogram_old.keys())
}  # sorted to dict
# print(histogram_old)
histogram_db = histogram_old.copy()