def img_array_resize(img,sz): """ Resize an image array using PIL. input: img can be array(must has two dimensions) or pil image. output: resized array """ t = Image.fromarray(uint8(img)) return array(t.resize(sz))
def filter_homemade(im): h,w = im.shape[0],im.shape[1] # cvt to gray level img = pl.zeros((h,w)) for i in xrange(h): for j in xrange(w): img[i,j] = int(pl.mean(im[i,j])) # low pass filter Ker = 1./16 * pl.array([[1,2,1],[2,4,2],[1,2,1]]) imf = pl.uint8(img.copy()) for i in xrange(1,h-1): for j in xrange(1,w-1): imf[i,j] = int(pl.sum(Ker * img[i-1:i+2,j-1:j+2])) return imf
from PIL import Image from pylab import imshow, show, axis, array, figure from pylab import gray, subplot, uint8 # load the image file img = Image.open('../../data/cv_data/empire.jpg') img = array(img) print img.min(), img.max() img = img * 1000 print img.min(), img.max() print img.shape, img.dtype img = uint8(img) print img.min(), img.max() print img.shape, img.dtype img_new = Image.fromarray(img) #the input array must be type of 'uinit8' imshow(img_new) show()
print area_mode #print img_bin,stats.mode(img_bin,axis=None) #print img_bin,np.max(img_bin) # do gaussian blur to the bin img #img_bin = filters.gaussian_filter(img_bin,0.26935) #print img_bin,stats.mode(img_bin,axis=None) #print img_bin,np.max(img_bin) # binary again #img_bin = filters.maximum_filter(img_bin,7) #img_bin = filter.threshold_adaptive(img_bin,7) #img_bin[img_bin>0]=255 Image.fromarray(uint8(img_bin)).save('feature_points.png') figure(); gray(); # don't use colors # show the two pics on 1*2 frame #subplot(1,3,1) imshow(img_gray) #subplot(1,3,2) figure(); gray(); # don't use colors imshow(img_bin) figure(); gray(); # don't use colors imshow(img_bin_words) #subplot(1,3,3) #imshow(labeled_array) #ob = labeled_array[obj_list[100]] figure(); gray(); # don't use colors
from PIL import Image from pylab import imshow, show, axis, array, zeros, uint8, imsave from pylab import jet # load the image file img = Image.open('../../data/cv_data/empire.jpg') img = array(img) #invert image im2 = 255 - img im3 = zeros(im2.shape) im3[15:15 + 10, 15:15 + 10] = 200 # im4 = uint8(im3) #Image.fromarray(im4).save('test.png') # im4 must be uinit8 type #http://docs.scipy.org/doc/scipy/reference/misc.html#scipy.misc.comb imsave('test.png', im4) print im4[15:15 + 10, 15:15 + 10] imshow(im4) show()
from PIL import Image from skimage.morphology import disk from skimage.color import rgb2hed from skimage.measure import label, regionprops print __doc__ glom_rgb = Image.open('s3.jpg') glom_gl = glom_rgb.convert('L') #Gray Level glom_hed = rgb2hed(glom_rgb) #hed glom_h = glom_hed[:, :, 0] #hematoxylim glom_h = ia.ianormalize(glom_h) selem = disk(10) #elemento estruturante glom_h = np.array(glom_h) glom_h = 255 - uint8(glom_h) #Segmentation glom_by_reconsTopHat = morph.closerecth(glom_h,selem) #reconstrução morfológicas de fechamento global_thresh = threshold_otsu(glom_by_reconsTopHat) #Otsu glom_bin = glom_by_reconsTopHat > global_thresh + global_thresh*0.1 glom_bin = img_as_ubyte(glom_bin) selem = disk(3) glom_seg = morph.open(glom_bin, selem) glom_seg = morph.close(glom_seg, selem) #Fechamento final #Mostra as etapas fig, axes = plt.subplots(2, 3, figsize=(14, 10)) fig.suptitle('Preprocessing, segmentation') ax1, ax2, ax3, ax4, ax5, ax6 = axes.ravel()
def imresize(im, sz): """ Resize an image array using PIL. """ pil_im = Image.fromarray(uint8(im)) return array(pil_im.resize(sz))
from PIL import Image from pylab import imshow,show,axis,array,zeros,uint8,imsave from pylab import jet # load the image file img = Image.open('../../data/cv_data/empire.jpg') img=array(img) #invert image im2 = 255 - img im3 = zeros(im2.shape) im3[15:15+10,15:15+10]=200 # im4 = uint8(im3) #Image.fromarray(im4).save('test.png') # im4 must be uinit8 type #http://docs.scipy.org/doc/scipy/reference/misc.html#scipy.misc.comb imsave('test.png', im4) print im4[15:15+10,15:15+10] imshow(im4) show()
print area_mode #print img_bin,stats.mode(img_bin,axis=None) #print img_bin,np.max(img_bin) # do gaussian blur to the bin img #img_bin = filters.gaussian_filter(img_bin,0.26935) #print img_bin,stats.mode(img_bin,axis=None) #print img_bin,np.max(img_bin) # binary again #img_bin = filters.maximum_filter(img_bin,7) #img_bin = filter.threshold_adaptive(img_bin,7) #img_bin[img_bin>0]=255 Image.fromarray(uint8(img_bin)).save('feature_points.png') figure() gray() # don't use colors # show the two pics on 1*2 frame #subplot(1,3,1) imshow(img_gray) #subplot(1,3,2) figure() gray() # don't use colors imshow(img_bin) figure() gray()
def savetofile(self,filename): deflatted = np.array(self.data) deflatted.shape = self.shape img = Image.fromarray(uint8(deflatted)) img.save(filename)
import pylab as pl from scipy.ndimage import filters from PIL import Image im = pl.array(Image.open("/home/aaryen/Desktop/empire.jpg")) im2 = pl.zeros(im.shape) for i in range(3): im2[:, :, i] = filters.gaussian_filter(im[:, :, i], 1) im2 = pl.uint8(im2) im_unsharp = im2 - im im_sharp = im - im_unsharp pl.figure() pl.title("Original") pl.imshow(im) pl.figure() pl.title("Gaussian Blur") pl.imshow(im2) pl.figure() pl.title("Unsharp") pl.imshow(im_unsharp) pl.figure() pl.title("Sharp") pl.imshow(im_sharp) pl.show()
def imresize(im, sz): '''使用 PIL 对象重新定义图像数组的大小''' from PIL import Image pil_im = Image.fromarray(uint8(im)) return array(pil_im.resize(sz))