Beispiel #1
0
			def thread_proc():
				while True:
					try:
						bucket = v_queue.get_nowait()
					except:
						break
					
					beta_mat_block=beta[:,:,(z_division*s_portion)+bucket]
					alpha_mat_block=alpha[:,:,(z_division*s_portion)+bucket]
		
					correction_mat_pixel=scsp.diags(Dimg_org[((z_division*s_portion)+bucket)*r_org*c_org:((z_division*s_portion)+bucket+1)*r_org*c_org],0)
					correction_mat2_pixel=scsp.eye(r_org*c_org,r_org*c_org)
					correction_mat_pixel=scsp.hstack([correction_mat_pixel,correction_mat2_pixel])
					del correction_mat2_pixel
		
					beta_mat_block=np.repeat(beta_mat_block,window_size_x,axis=0)	
					beta_mat=np.repeat(beta_mat_block,window_size_y,axis=1)	
					del beta_mat_block
					beta_mat=np.uint16((float(1)/float(accuracy1))*beta_mat)
					beta_changed=rank.bilateral_mean(beta_mat,selem=selem,s0=lower_val_beta,s1=upper_val_beta)
					beta_changed=(np.float32(beta_changed))*float(accuracy1)
					del beta_mat
					beta_vec=np.reshape(beta_changed,(r_org*c_org,1),order='F')
					alpha_mat_block=np.repeat(alpha_mat_block,window_size_x,axis=0)	
					alpha_mat=np.repeat(alpha_mat_block,window_size_y,axis=1)	
					del alpha_mat_block
					alpha_mat=alpha_mat+cnst
					alpha_mat=np.uint16((float(1)/float(accuracy2))*alpha_mat)
					alpha_changed=rank.bilateral_mean(alpha_mat,selem=selem,s0=lower_val_alpha,s1=upper_val_alpha)
					alpha_changed=((np.float32(alpha_changed))*float(accuracy2))-cnst
					del alpha_mat
					alpha_vec=np.reshape(alpha_changed,(r_org*c_org,1),order='F')
					param_vec=np.vstack([beta_vec,alpha_vec])
					corrected_data_smoothed=correction_mat_pixel*param_vec
					corrected_data_smoothed=np.reshape(corrected_data_smoothed,(r_org,c_org),order='F')
			
					num_finished = 0
					with finished_count.get_lock():
						finished_count.value += 1
						num_finished = finished_count.value
					#print '  Finished %d/%d' % (num_finished, buckets)
					with value_portion_arr.get_lock():
						value_portion[...][:,:,bucket]=corrected_data_smoothed
that restricts the local neighborhood to pixel having a greylevel similar to
the central one.

.. note::

    a different implementation is available for color images in
    `skimage.filter.denoise_bilateral`.

"""

from skimage.filter.rank import bilateral_mean

ima = data.camera()
selem = disk(10)

bilat = bilateral_mean(ima.astype(np.uint16), disk(20), s0=10, s1=10)

# display results
fig = plt.figure(figsize=[10, 7])
plt.subplot(2, 2, 1)
plt.imshow(ima, cmap=plt.cm.gray)
plt.xlabel('original')
plt.subplot(2, 2, 3)
plt.imshow(bilat, cmap=plt.cm.gray)
plt.xlabel('bilateral mean')
plt.subplot(2, 2, 2)
plt.imshow(ima[200:350, 350:450], cmap=plt.cm.gray)
plt.subplot(2, 2, 4)
plt.imshow(bilat[200:350, 350:450], cmap=plt.cm.gray)
"""
that restricts the local neighborhood to pixel having a gray-level similar to
the central one.

.. note::

    A different implementation is available for color images in
    `skimage.filter.denoise_bilateral`.

"""

from skimage.filter.rank import bilateral_mean

noisy_image = img_as_ubyte(data.camera())
selem = disk(10)

bilat = bilateral_mean(noisy_image.astype(np.uint16), disk(20), s0=10, s1=10)

fig = plt.figure(figsize=[10, 7])

plt.subplot(2, 2, 1)
plt.imshow(noisy_image, cmap=plt.cm.gray)
plt.title('Original')
plt.axis('off')

plt.subplot(2, 2, 3)
plt.imshow(bilat, cmap=plt.cm.gray)
plt.title('Bilateral mean')
plt.axis('off')

plt.subplot(2, 2, 2)
plt.imshow(noisy_image[200:350, 350:450], cmap=plt.cm.gray)
that restricts the local neighborhood to pixel having a greylevel similar to
the central one.

.. note::

    a different implementation is available for color images in
    `skimage.filter.denoise_bilateral`.

"""

from skimage.filter.rank import bilateral_mean

ima = data.camera()
selem = disk(10)

bilat = bilateral_mean(ima.astype(np.uint16), disk(20), s0=10, s1=10)

# display results
fig = plt.figure(figsize=[10, 7])
plt.subplot(2, 2, 1)
plt.imshow(ima, cmap=plt.cm.gray)
plt.xlabel('original')
plt.subplot(2, 2, 3)
plt.imshow(bilat, cmap=plt.cm.gray)
plt.xlabel('bilateral mean')
plt.subplot(2, 2, 2)
plt.imshow(ima[200:350, 350:450], cmap=plt.cm.gray)
plt.subplot(2, 2, 4)
plt.imshow(bilat[200:350, 350:450], cmap=plt.cm.gray)

"""
that restricts the local neighborhood to pixel having a gray-level similar to
the central one.

.. note::

    A different implementation is available for color images in
    `skimage.filter.denoise_bilateral`.

"""

from skimage.filter.rank import bilateral_mean

noisy_image = img_as_ubyte(data.camera())
selem = disk(10)

bilat = bilateral_mean(noisy_image.astype(np.uint16), disk(20), s0=10, s1=10)

fig = plt.figure(figsize=[10, 7])

plt.subplot(2, 2, 1)
plt.imshow(noisy_image, cmap=plt.cm.gray)
plt.title('Original')
plt.axis('off')

plt.subplot(2, 2, 3)
plt.imshow(bilat, cmap=plt.cm.gray)
plt.title('Bilateral mean')
plt.axis('off')

plt.subplot(2, 2, 2)
plt.imshow(noisy_image[200:350, 350:450], cmap=plt.cm.gray)
complete image (background and details). Bilateral mean exhibits a high
filtering rate for continuous area (i.e. background) while higher image
frequencies remain untouched.

"""
import numpy as np
import matplotlib.pyplot as plt

from skimage import data
from skimage.morphology import disk
import skimage.filter.rank as rank

a16 = (data.coins()).astype(np.uint16) * 16
selem = disk(20)

f1 = rank.percentile_mean(a16, selem=selem, p0=.1, p1=.9)
f2 = rank.bilateral_mean(a16, selem=selem, s0=500, s1=500)
f3 = rank.mean(a16, selem=selem)

# display results
fig, axes = plt.subplots(nrows=3, figsize=(15, 10))
ax0, ax1, ax2 = axes

ax0.imshow(np.hstack((a16, f1)))
ax0.set_title('percentile mean')
ax1.imshow(np.hstack((a16, f2)))
ax1.set_title('bilateral mean')
ax2.imshow(np.hstack((a16, f3)))
ax2.set_title('local mean')
plt.show()