def sart_tvm(tils, angles, tau=0.2, round_num=5, tvm_iteration=200, relaxation=0.3): import rof # print("--start sart_tvm---") denoise_TVM = None for epoch in range(round_num): # SART if epoch == 0: recon_SART = iradon_sart(tils, theta=angles, image=None, relaxation=relaxation) else: recon_SART = iradon_sart(tils, theta=angles, image=denoise_TVM, relaxation=relaxation) unit_tvm = np.zeros(recon_SART.shape) image = rof.denoise(recon_SART, unit_tvm, tau=tau, Ngrad=tvm_iteration)[0] return image
def test(): im = zeros((500, 500)) im[100:400, 100:400] = 128 im[200:300, 200:300] = 255 im = im + 30 * random.standard_normal((500, 500)) from scipy.misc import imsave imsave('synth_orgin.jpg', im) return U, T = rof.denoise(im, im) G = filters.gaussian_filter(im, 10) imsave('synth_rof.jpg', U) imsave('synth_gaussian.jpg', G)
def test(): im = zeros((500, 500)) im[100:400,100:400] = 128 im[200:300,200:300] = 255 im = im + 30*random.standard_normal((500, 500)) from scipy.misc import imsave imsave('synth_orgin.jpg', im) return U,T = rof.denoise(im, im) G = filters.gaussian_filter(im, 10) imsave('synth_rof.jpg', U) imsave('synth_gaussian.jpg', G)
from PIL import Image import numpy import rof import stereo im_l = numpy.array(Image.open('./data/ppm/scene1.row3.col3.ppm').convert('L'), 'f') im_r = numpy.array(Image.open('./data/ppm/scene1.row3.col4.ppm').convert('L'), 'f') steps = 12 start = 4 wid = 9 res = stereo.plane_sweep_ncc(im_l, im_r, start, steps, wid) res, _ = rof.denoise(res, res, tv_weight=80/255.0, tolerance=0.01) import scipy.misc scipy.misc.imsave('./output/depth_rof.png', res)
import numpy as np from scipy.ndimage import filters import rof from matplotlib import pyplot as plt from PIL import Image # now lets see how the ROF algorithm handles real images im2 = np.array(Image.open('Image 4_z34.tif')) U2, T2 = rof.denoise(im2, im2) plt.subplot(121), plt.imshow(im2,'gray'), plt.title('Original Image') plt.axis('equal'), plt.axis('off') plt.subplot(122), plt.imshow(U2,'gray'), plt.title('ROF denoising') plt.axis('equal'), plt.axis('off') plt.show()
from pylab import * from scipy import misc import numpy import rof im = misc.lena() #im = im + 20 * numpy.random.standard_normal(im.shape) U, T = rof.denoise(im, im, tv_weight=30, tolerance=0.01) gray() subplot(1, 2, 1) imshow(im) subplot(1, 2, 2) imshow(U) show()
im2H = getHisteq(im2Quotient) Image.fromarray(im2H).convert('RGB').save( 'Lab1/Histeq on Quotient gaussian blur of 2 gray.png') im3H = getHisteq(im3Quotient) Image.fromarray(im3H).convert('RGB').save( 'Lab1/Histeq on Quotient gaussian blur of 5 gray.png') im4H = getHisteq(im4Quotient) Image.fromarray(im4H).convert('RGB').save( 'Lab1/Histeq on Quotient gaussian blur of 10 gray.png') temp = getHisteq(array(Image.open('dark.jpg').convert('L'))) temp = array(temp, 'uint8') Image.fromarray(temp).convert('RGB').save( 'Lab1/Histeq on dark image sample.png') temp = getHisteq(array(Image.open('bright.jpg').convert('L'))) temp = array(temp, 'uint8') Image.fromarray(temp).convert('RGB').save( 'Lab1/Histeq on bright image sample.png') #RUDIN OSHER FATEMI ON BLURRED WITH GAMMA 2,5,10 AND OTHER SAMPLE IMAGES (SALT AND PEPPER NOISE) temp = rof.denoise(im2Gray, im2Gray) Image.fromarray(temp).convert('RGB').save('Lab1/rof on gamma blur 2.png') temp = rof.denoise(im3Gray, im3Gray) Image.fromarray(temp).convert('RGB').save('Lab1/rof on gamma blur 5.png') temp = rof.denoise(im4Gray, im4Gray) Image.fromarray(temp).convert('RGB').save('Lab1/rof on gamma blur 10.png') salted = array(Image.open('salted.jpg').convert('L')) temp = rof.denoise(salted, salted) Image.fromarray(temp).convert('RGB').save('Lab1/rof on salt noise.png') peppered = array(Image.open('peppered.jpg').convert('L')) temp = rof.denoise(peppered, peppered) Image.fromarray(temp).convert('RGB').save('Lab1/rof on pepper noise.png')
def update(val): U, _ = rof.denoise(im, im, tv_weight=srof.val, tolerance=0.01) subplot(1, 2, 2) imshow(U) draw()
import rof from pylab import * from PIL import Image # import scipy.misc import imageio from skimage import * im1 = array(Image.open('../data/flower32_t0.png').convert("L")) im2 = array(Image.open('../data/ceramic-houses_t0.png').convert("L")) U1, T1 = rof.denoise(im1, im1, tolerance=0.001) U2, T2 = rof.denoise(im2, im2, tolerance=0.001) t1 = 0.8 # flower32_t0 threshold t2 = 0.4 # ceramic-houses_t0 threshold seg_im1 = img_as_uint(U1 < t1*U1.max()) seg_im2 = img_as_uint(U2 < t2*U2.max()) fig = figure() gray() subplot(231) axis('off') imshow(im1) subplot(232) axis('off') imshow(U1) subplot(233) axis('off')
Created on Sun Aug 14 21:14:44 2016 @author: user """ from numpy import * from numpy import random from pylab import * from scipy.ndimage import filters import rof # create synthetic image with noise im = zeros((500,500)) im[100:400,100:400] = 128 im[200:300,200:300] = 255 '''add in noise''' im = im + 30*random.standard_normal((500,500)) imshow(im) U,T = rof.denoise(im,im) G = filters.gaussian_filter(im,10) im1 = array(Image.open('baby_1.jpg').convert('L')) U,T = rof.denoise(im1,im1) figure() gray() imshow(U) axis('equal') axis('off') show() # save the result import scipy.misc scipy.misc.imsave('synth_rof.pdf',U) scipy.misc.imsave('synth_gaussian.pdf',G)
import ncut from scipy.misc import imresize from PIL import Image from numpy import * from pylab import * import sys sys.path.append('../ch1/') import rof im2 = array(Image.open('../pcv_data/data/C-uniform03.ppm')) im1 = array(Image.open('../pcv_data/data/alcatraz1.jpg')) im = array(Image.open('../pcv_data/data/ceramic-houses_t0.png').convert("L")) U, T = rof.denoise(im, im, tolerance=0.001) t = 0.4 #threshold m, n = im.shape[:2] # resize image to (wid,wid) wid = 50 rim = imresize(im, (wid, wid), interp='bilinear') rim = array(rim, 'f') # create normalized cut matrix A = ncut.ncut_graph_matrix(rim, sigma_d=1, sigma_g=1e-2) # cluster code, V = ncut.cluster(A, k=3, ndim=3) # reshape to original image size codeim = imresize(code.reshape(wid, wid), (m, n), interp='nearest') # plot result
from PIL import Image, ImageFilter from pylab import * import rof import cv2 import pytesseract ims = Image.open('D:\\work\\tesseract\\testing\\scan009.jpg').convert('L') ims = ims.filter(ImageFilter.SHARPEN) thresh = 250 fn = lambda x: 255 if x > thresh else 0 ims.point(fn, mode='1') im = array(ims) #im = im.convert('L').point(fn, mode='1') U, T1 = rof.denoise(im, im, 0.2, 0.125, 100) figure() gray() imshow(U) axis('equal') axis('off') show() show() #pil_im = Image.fromarray(U) #pil_im.save("rof"+str(i*10)+".jpg") nim = Image.fromarray(U) print( pytesseract.image_to_string(nim, lang='lat+eng', config='--dpi 200 --psm 4'))
def get_image(name): na = 'E:/PycharmProjects/ver_image/image/'+name enhancer = ImageEnhance.Contrast(Image.open(na).resize((189, 67)).convert("L")) image_enhancer = enhancer.enhance(4) im = array(image_enhancer) bins = 256 imhist, bins = histogram(im.flatten(), bins) cdf = imhist.cumsum() cdf = 255 * cdf / cdf[-1] im2 = interp(im.flatten(), bins[:-1], cdf) U, T = rof.denoise(im2.reshape(im.shape), im2.reshape(im.shape)) arr = array(U) for i in range(arr.shape[1]-1): if arr[0][i] < 250: arr[1][i] = 255 arr[2][i] = 255 arr[3][i] = 255 for i in range(arr.shape[0]-1): arr[i][arr.shape[1]-1] = 255 arr[i-1][arr.shape[1]-1] = 255 arr[i-2][arr.shape[1]-1] = 255 arr[i][arr.shape[1]-2] = 255 arr[i-1][arr.shape[1]-2] = 255 arr[i-2][arr.shape[1]-2] = 255 for i in range(arr.shape[0]-6, arr.shape[0]-1): for j in range(arr.shape[1]-1): arr[i][j] = 255 for i in range(arr.shape[1]-5, arr.shape[1]-1): for j in range(arr.shape[0]-1): arr[j][i] = 255 for i in range(0, 5): for j in range(arr.shape[0]-1): arr[j][i] = 255 i = 4 j = 4 while i < array(U).shape[0]-6: while j < array(U).shape[1]-6: if arr[i][j] < 200 or arr[i][j-5] < 200 or arr[i][j+5] < 200 or arr[i+5][j] < 200 \ or arr[i-5][j] < 200 or arr[i+5][j+5] < 200 or arr[i-5][j-5] < 200 or arr[i-5][j+5] < 200: for k in range(i-6, i+6): for l in range(j-6, j+6): arr[k][l] = 255 j += 1 i += 1 w = array(U).shape[0]-5 h = array(U).shape[1]-5 while w > 4: while h > 4: if (arr[i][j] < 200) or (arr[i-5][j-5] < 200) or (arr[i][j-5] < 200) or (arr[i+5][j-5] < 200) \ or arr[i-5][j] < 200 or arr[i+5][j] < 200 or arr[i-5][j+5] < 200 or arr[i+5][j+5] < 200\ or arr[i-3][j-3] < 200 or arr[i][j-3] < 200 or arr[i+3][j-3] < 200 \ or arr[i-3][j] < 200 or arr[i+3][j] < 200 or arr[i-3][j+3] < 200 or arr[i+3][j+3] < 200: for k in range(i-6, i+6): for l in range(j-6, j+6): arr[k][l] = 255 h -= 1 w -= 1 while i < array(U).shape[0]-3: while j < array(U).shape[1]-3: if arr[i][j] < 200 or arr[i][j-3] < 200 or arr[i][j+3] < 200 or arr[i+3][j] < 200 or arr[i-3][j] < 200: for k in range(i-3, i+3): for l in range(j-3, j+3): arr[k][l] = 255 j += 1 i += 1 pil_im = Image.fromarray(arr) data = pil_im.getdata() w, h = pil_im.size black_point = 0 for x in xrange(1, w-1): for y in xrange(1, h-1): mid_pixel = data[w*y+x] # 中央像素点像素值 if mid_pixel < 150: # 找出上下左右四个方向像素点像素值 pil_im.putpixel((x, y), 255) pil_im.putpixel((x-1, y-1), 255) pil_im.putpixel((x, y-1), 255) pil_im.putpixel((x+1, y-1), 255) pil_im.putpixel((x-1, y), 255) pil_im.putpixel((x+1, y), 255) pil_im.putpixel((x-1, y+1), 255) pil_im.putpixel((x, y+1), 255) pil_im.putpixel((x+1, y+1), 255) pil_im = array(arr - array(pil_im)) pil_im = Image.fromarray(uint8(pil_im)) data = pil_im.getdata() w, h = pil_im.size for x in xrange(1, w-1): for y in xrange(1, h-1): mid_pixel = data[w*y+x] # 中央像素点像素值 if mid_pixel == 0: # 找出上下左右四个方向像素点像素值 pil_im.putpixel((x, y), 255) pil_im.putpixel((x, y-1), 255) pil_im.putpixel((x-1, y), 255) pil_im.putpixel((x+1, y), 255) pil_im.putpixel((x, y+1), 255) return pil_im.resize((80, 30))
from pylab import * from scipy.ndimage import filters import numpy import rof im = numpy.zeros((500, 500)) im[100:400, 100:400] = 128 im[200:300, 200:300] = 255 im_noise = im + 30 * numpy.random.standard_normal((500, 500)) U, T = rof.denoise(im_noise, im_noise, tv_weight=100) G = filters.gaussian_filter(im_noise, 10) gray() subplot(2, 2, 1) imshow(im) subplot(2, 2, 2) imshow(im_noise) subplot(2, 2, 3) imshow(U) subplot(2, 2, 4) imshow(G) show()
def test2(): im = array(Image.open('data/empire.jpg').convert('L')) U,T = rof.denoise(im,im) showim(U)
# -*- coding: utf-8 -*- """ Created on Fri May 16 15:37:09 2014 @author: admin """ import rof from numpy import * im=array(Image.open('empire.jpg').convert('L')) U,T=rof.denoise(im,im,tolerance=0.001) t=0.4#threshold import scipy.misc scipy.misc.imsave('result.pdf',U<t*U.max())
from numpy import * from numpy import random from PIL import Image from scipy.ndimage import filters import rof # create synthetic image with noise im = zeros((500, 500)) im[100:400, 100:400] = 128 im[200:300, 200:300] = 255 im = im + 30 * random.standard_normal((500, 500)) U, T = rof.denoise(im, im) G = filters.gaussian_filter(im, 10) G = array(G, 'uint8') G = Image.fromarray(uint8(G)) G.show()
from numpy import * from numpy import random from scipy.ndimage import filters import rof from scipy.misc import imsave im = zeros((500, 500)) im[100:400, 100:400] = 128 im[200:300, 200:300] = 255 im = im + 30 * random.standard_normal((500, 500)) imsave('synth_ori.pdf', im) U, T = rof.denoise(im, im, 0.07) G = filters.gaussian_filter(im, 10) imsave('synth_rof.pdf', U) imsave('synth_gaussian.pdf', G)
def test2(): im = array(Image.open('data/empire.jpg').convert('L')) U, T = rof.denoise(im, im) showim(U)
# 1.4.4.2 配列を画像として保存する im = np.array(Image.open("empire.jpg")) # imに画像の配列を入れる imsave("test.jpg", im) # 配列を直接画像ファイルに保存 lena = scipy.misc.lena() plt.imshow(lena) # 1.5 画像のノイズ除去 # ノイズを含む画像を合成する im = np.zeros((500, 500)) im[100:400, 100:400] = 128 im[200:300, 200:300] = 255 im = im + 30 * random.standard_normal((500, 500)) U, T = rof.denoise(im, im) G = filters.gaussian_filter(im, 10) imsave("synth_rof.pdf", U) # 結果を保存 imsave("synth_gaussian.pdf", G) plt.figure() plt.gray() plt.imshow(im) plt.figure() plt.gray() plt.imshow(G) plt.figure() plt.gray() plt.imshow(U)
from PIL import Image import numpy import rof import stereo im_l = numpy.array(Image.open('out_stereo1.ppm').convert('L'), 'f') im_r = numpy.array(Image.open('out_stereo2.ppm').convert('L'), 'f') steps = 12 start = 4 wid = 9 res = stereo.plane_sweep_ncc(im_l, im_r, start, steps, wid) res, _ = rof.denoise(res, res, tv_weight=80 / 255.0, tolerance=0.01) import scipy.misc scipy.misc.imsave('out_depth_rof.png', res)
def btnDenoiseEvent(self, event): """使用ROF去噪模型对灰度图去噪""" assert self.picName != None # 确保已经有图片打开 self.im, T = rof.denoise(self.im, self.im) self.displayImage()
import numpy as np from scipy.ndimage import filters import rof from matplotlib import pyplot as plt from PIL import Image # create a synthetic image with noise im = np.zeros((500,500)) im[100:400 , 100:400] = 128 im[200:300, 200:300] = 255 im = np.array(im, 'uint8') # add some noise im = im + 30*np.random.standard_normal((500,500)) U, T = rof.denoise(im, im) G = filters.gaussian_filter(im,10) # plot result plt.figure(1) plt.subplot(131), plt.imshow(im,'gray'), plt.title('Original Image') plt.axis('off') plt.subplot(132), plt.imshow(G,'gray'), plt.title('Gaussian Filter') plt.axis('off') plt.subplot(133), plt.imshow(U,'gray'), plt.title('ROF denoising') plt.axis('off') # now lets see how the ROF algorithm handles real images im2 = np.array(Image.open('building.jpg').convert('L')) U2, T2 = rof.denoise(im2, im2)