示例#1
0
def create_dat(im, conf):
    mode = im.mode
    xsize, ysize = im.size
    if mode not in ['L', '1']:
        show_error(
            'Simulations for this module just supports Gray-scale and binary images, check your images !'
        )
    if xsize != 512:
        show_error(
            'Simulations for this module just supports 512xN images, check your images !'
        )
    if conf['width'] not in [3, 5]:
        show_error(
            '''Simulations for this module just supports conf "width" 3 and 5, check your images !'''
        )
    rows = RG(im, conf['width'])
    data_res = ''
    while not rows.frame_empty():
        row = rows.update()
        row.reverse()
        for p in row:
            if mode == '1':
                p = 0 if p == 0 else 1
            data_res += color_format(mode, p)
        data_res += '\n'
    return data_res[:-1]
示例#2
0
def transform(im, conf):
    mode = im.mode
    template = conf['template']
    if mode not in ['1']:
        show_error(
            'Simulations for this module just supports binary images, check your images !'
        )
    for row in template:
        if len(template) != len(row):
            show_error(
                'every row in "template" must equal to length of template, check your conf !'
            )
        if len(template) not in [3, 5]:
            show_error(
                'size of "template" must equal to e or 5, check your conf !')
        for p in row:
            if p not in [0, 1]:
                show_error(
                    'Elements in "template" must equal to 0 or 1, check your conf !'
                )
    template = eval(str(template).replace('1', '255'))
    width = len(template)
    data_res = []
    rows = RG(im, width)
    window = WG(width)
    while not rows.frame_empty():
        win = window.update(rows.update())
        if not window.is_enable():
            continue
        data_res.append(1 if win == template else 0)
    im_res = Image.new('1', im.size)
    im_res.putdata(data_res)
    return im_res
示例#3
0
def create_dat(im, conf):
    mode = im.mode
    width = int(conf['window_width'])
    half_width = width >> 1
    full_half_width = width * width >> 1
    fil = conf['filter']
    if mode not in ['L']:
        show_error(
            'Simulations for this module just supports Gray-scale images, check your images !'
        )
    if fil not in ['mean', 'mid']:
        show_error(
            '"filter" just supports "mean" and "mid"m check your conf !')
    data_res = ''
    rows = RG(im, width)
    window = WG(width)
    while not rows.frame_empty():
        win = window.update(rows.update())
        if not window.is_enable():
            continue
        data_res += '%s\n' % color_format(mode, win[half_width][half_width])
        if fil == 'mean':
            data_res += '%s\n' % color_format(mode, mean_filter(win))
        else:
            data_res += '%s\n' % color_format(
                mode, rank_filter(win, full_half_width))
    return data_res[:-1]
示例#4
0
def debug(im, conf):
    mode = im.mode
    template = conf['template']
    if mode not in ['1']:
        show_error(
            'Simulations for this module just supports binary images, check your images !'
        )
    for row in template:
        if len(template) != len(row):
            show_error(
                'every row in "template" must equal to length of template, check your conf !'
            )
        if len(template) not in [3, 5]:
            show_error(
                'size of "template" must equal to e or 5, check your conf !')
        for p in row:
            if p not in [0, 1]:
                show_error(
                    'Elements in "template" must equal to 0 or 1, check your conf !'
                )
    width = len(template)
    data_res = ''
    rows = RG(im, width)
    window = WG(width)
    while not rows.frame_empty():
        win = window.update(rows.update())
        if not window.is_enable():
            continue
        data_res += '%d\n' % 1 if win == template else 0
    return data_res
示例#5
0
def create_dat(im, conf):
    mode = im.mode
    width = int(conf['window_width'])
    rank = int(conf['rank'])
    if mode not in ['L']:
        show_error(
            'Simulations for this module just supports Gray-scale images, check your images !'
        )
    if width not in [3, 5]:
        show_error(
            'Simulations for this module just supports "window_width" 3 and 5, check your conf !'
        )
    if rank < 0 or rank > width * width - 1:
        show_error(
            '"rank" must greater than 0 and less than window * window - 1, check your conf !'
        )
    xsize, ysize = im.size
    data_res = ''
    rows = RG(im, width)
    window = WG(width)
    while not rows.frame_empty():
        win = window.update(rows.update())
        if not window.is_enable():
            continue
        win.reverse()
        for row in win:
            row = list(row)
            row.reverse()
            for p in row:
                data_res += color_format(mode, p)
        data_res += '\n'
    return data_res[:-1]
示例#6
0
def create_dat(im, conf):
	mode = im.mode
	template = conf['template']
	if mode not in ['1']:
		show_error('Simulations for this module just supports binary images, check your images !')
	for row in template:
		if len(template) != len(row):
			show_error('every row in "template" must equal to length of template, check your conf !')
		if len(template) not in [3, 5]:
			show_error('size of "template" must equal to e or 5, check your conf !')
		for p in row:
			if p not in [0, 1]:
				show_error('Elements in "template" must equal to 0 or 1, check your conf !')
	width = len(template)
	data_res = ''
	rows = RG(im, width)
	window = WG(width)
	while not rows.frame_empty():
		win = window.update(rows.update())
		if not window.is_enable():
			continue
		win.reverse()
		for row in win:
			row = list(row)
			row.reverse()
			for p in row:
				data_res += color_format(mode, p)
		data_res += '\n'
	return data_res[:-1]
示例#7
0
def debug(im, conf):
	mode = im.mode
	template = conf['template']
	ed_mode = conf['mode']
	if mode not in ['L']:
		show_error('Simulations for this module just supports binary images, check your images !')
	if ed_mode not in ['Erosion', 'Dilation']:
		show_error('"mode" just supports "Erosion" and "Dilation", check your conf !')
	for row in template:
		if len(template) != len(row):
			show_error('every row in "template" must equal to length of template, check your conf !')
		if len(template) not in [3, 5]:
			show_error('size of "template" must equal to e or 5, check your conf !')
		for p in row:
			if p not in [0, 1]:
				show_error('Elements in "template" must equal to 0 or 1, check your conf !')
	ed_mode = 0 if ed_mode == 'Erosion' else 1
	width = len(template)
	data_res = ''
	rows = RG(im, width)
	window = WG(width)
	while not rows.frame_empty():
		win = window.update(rows.update())
		if not window.is_enable():
			continue
		pix = 1
		for wy in xrange(width):
			for wx in xrange(width):
				p_w = w[wy][wx] ^ ed_mode
				p_w = p_w | ~mask[wy][wx]
				pix = pix & p_w
		pix = pix ^ ed_mode
		data_res += '%d\n' % pix
	return data_res
示例#8
0
def transform(im, conf):
    mode = im.mode
    width = int(conf['window_width'])
    half_width = width >> 1
    full_half_width = width * width >> 1
    fil = conf['filter']
    if mode not in ['L']:
        show_error(
            'Simulations for this module just supports Gray-scale images, check your images !'
        )
    if fil not in ['mean', 'mid']:
        show_error(
            '"filter" just supports "mean" and "mid"m check your conf !')
    data_res = []
    rows = RG(im, width)
    window = WG(width)
    while not rows.frame_empty():
        win = window.update(rows.update())
        if not window.is_enable():
            continue
        if fil == 'mean':
            data_res.append(
                1 if win[half_width][half_width] >= mean_filter(win) else 0)
        else:
            data_res.append(1 if win[half_width][half_width] >= rank_filter(
                win, full_half_width) else 0)
    im_res = Image.new('1', im.size)
    im_res.putdata(data_res)
    return im_res
示例#9
0
def debug(im, conf):
    mode = im.mode
    width = int(conf['window_width'])
    half_width = width >> 1
    full_half_width = width * width >> 1
    fil = conf['filter']
    if mode not in ['L']:
        show_error(
            'Simulations for this module just supports Gray-scale images, check your images !'
        )
    if fil not in ['mean', 'mid']:
        show_error(
            '"filter" just supports "mean" and "mid"m check your conf !')
    data_src = im.getdata()
    data_res = ''
    rows = RG(im, width)
    window = WG(width)
    while not rows.frame_empty():
        win = window.update(rows.update())
        if not window.is_enable():
            continue
        if fil == 'mean':
            data_res += '1' if mean_filter(
                win) >= win[half_width][half_width] else '0'
        else:
            data_res += '1' if rank_filter(
                win, full_half_width) >= win[half_width][half_width] else '0'
    return data_res
示例#10
0
def transform(im, conf):
    mode = im.mode
    width = int(conf['window_width'])
    rank = int(conf['rank'])
    if mode not in ['L']:
        show_error(
            'Simulations for this module just supports Gray-scale images, check your images !'
        )
    if width not in [3, 5]:
        show_error(
            'Simulations for this module just supports "window_width" 3 and 5, check your conf !'
        )
    if rank < 0 or rank > width * width - 1:
        show_error(
            '"rank" must greater than 0 and less than window * window - 1, check your conf !'
        )
    data_res = []
    rows = RG(im, width)
    window = WG(width)
    while not rows.frame_empty():
        win = window.update(rows.update())
        if not window.is_enable():
            continue
        data_res.append(rank_filter(win, rank))
    im_res = Image.new('L', im.size)
    im_res.putdata(data_res)
    return im_res
示例#11
0
def debug(im, conf):
    mode = im.mode
    width = int(conf['window_width'])
    rank = int(conf['rank'])
    if mode not in ['L']:
        show_error(
            'Simulations for this module just supports Gray-scale images, check your images !'
        )
    if width not in [3, 5]:
        show_error(
            'Simulations for this module just supports "window_width" 3 and 5, check your conf !'
        )
    if rank < 0 or rank > width * width - 1:
        show_error(
            '"rank" must greater than 0 and less than window * window - 1, check your conf !'
        )
    data_src = im.getdata()
    data_res = ''
    rows = RG(im, width)
    window = WG(width)
    while not rows.frame_empty():
        win = window.update(rows.update())
        if not window.is_enable():
            continue
        data_res += '%d\n' % rank_filter(win, rank)
    return data_res
示例#12
0
def debug(im, conf):
    mode = im.mode
    width = int(conf['window_width'])
    if mode not in ['L']:
        show_error(
            'Simulations for this module just supports Gray-scale images, check your images !'
        )
    if width not in [3, 5]:
        show_error(
            'Simulations for this module just supports "window_width" 3 and 5, check your conf !'
        )
    data_src = im.getdata()
    data_res = ''
    rows = RG(im, width)
    window = WG(width)
    while not rows.frame_empty():
        win = window.update(rows.update())
        if not window.is_enable():
            continue
        data_res += '%d\n' % mean_fitter(win)
    return data_res
示例#13
0
def transform(im, conf):
    mode = im.mode
    width = int(conf['window_width'])
    if mode not in ['L']:
        show_error(
            'Simulations for this module just supports Gray-scale images, check your images !'
        )
    if width not in [3, 5]:
        show_error(
            'Simulations for this module just supports "window_width" 3 and 5, check your images !'
        )
    data_res = []
    rows = RG(im, width)
    window = WG(width)
    while not rows.frame_empty():
        win = window.update(rows.update())
        if not window.is_enable():
            continue
        data_res.append(mean_filter(win))
    im_res = Image.new('L', im.size)
    im_res.putdata(data_res)
    return im_res
示例#14
0
def debug(im, conf):
	mode = im.mode
	xsize = im.size[0]
	if mode not in ['L', '1']:
		show_error('Simulations for this module just supports Gray-scale and binary images, check your images !')
	if xsize != 512:
		show_error('Simulations for this module just supports 512xN images, check your images !')
	if conf['width'] not in [3, 5]:
		show_error('''Simulations for this module just supports conf "width" 3 and 5, check your images !''')
	rows = RG(im, conf['width'])
	window = WG(conf['width'])
	data_res = ''
	while not rows.frame_empty():
		win = window.update(rows.update())
		if not window.is_enable():
			continue
		for row in win:
			row = str(row)
			if mode == '1':
				row = row.replace('255', '1')
			data_res += '%s\n' % row.replace('[', '').replace(']', '').replace(',', '')
		data_res += '\n'
	return data_res[:-1]
示例#15
0
def transform(im, conf):
	mode = im.mode
	template = conf['template']
	ed_mode = conf['mode']
	if mode not in ['1']:
		show_error('Simulations for this module just supports binary images, check your images !')
	if ed_mode not in ['Erosion', 'Dilation']:
		show_error('"mode" just supports "Erosion" and "Dilation", check your conf !')
	for row in template:
		if len(template) != len(row):
			show_error('every row in "template" must equal to length of template, check your conf !')
		if len(template) not in [3, 5]:
			show_error('size of "template" must equal to e or 5, check your conf !')
		for p in row:
			if p not in [0, 1]:
				show_error('Elements in "template" must equal to 0 or 1, check your conf !')
	ed_mode = 0 if ed_mode == 'Erosion' else 1
	width = len(template)
	data_res = []
	rows = RG(im, width)
	window = WG(width)
	while not rows.frame_empty():
		win = window.update(rows.update())
		if not window.is_enable():
			continue
		pix = 1
		for wy in xrange(width):
			for wx in xrange(width):
				w = 0 if win[wy][wx] == 0 else 1 
				p_w = w ^ ed_mode
				p_w = p_w | ~template[wy][wx]
				pix = pix & p_w
		pix = pix ^ ed_mode
		data_res.append(pix)
	im_res = Image.new('1', im.size)
	im_res.putdata(data_res)
	return im_res
示例#16
0
def debug(im, conf):
    mode = im.mode
    xsize = im.size[0]
    if mode not in ['L', '1']:
        show_error(
            'Simulations for this module just supports Gray-scale and binary images, check your images !'
        )
    if xsize != 512:
        show_error(
            'Simulations for this module just supports 512xN images, check your images !'
        )
    if conf['width'] not in [3, 5]:
        show_error(
            '''Simulations for this module just supports conf "width" 3 and 5, check your images !'''
        )
    rows = RG(im, conf['width'])
    data_res = 'Showed row1 -> rowN\nBut the lowest color_width-bits of this are the first row !\n\n'
    while not rows.frame_empty():
        row = str(rows.update())
        if mode == '1':
            row = row.replace('255', '1')
        data_res += '%s\n' % row.replace('[', '').replace(']', '').replace(
            ',', '')
    return data_res[:-1]