0 like 0 dislike
1 view
in Python by anonymous Bilge (165k points)
python 2d array verisi ile image göstermek

5 Answers

0 like 0 dislike
by anonymous Bilge (165k points)

Aşağıda bir image 3d array'e çevriliyor (r,g,b) ve daha sonra 2d'ye düşürülüyor. Daha sonra eldeki veri ile tekrar bir image oluşturuluyor. imshow metodu iki parametre alıyor, bunlar ile matrix yine 3d ye tamamlanıyor ve gösteriliyor.

cmap-> grayscale modunda göstermesi için. başka color map'te kullanılabilir.cmap='gray' şeklinde parametre verilir.

interpolation : diğer matrixler benzer şekilde birinci matrixten türetiliyor.

from PIL import Image
import numpy as np
import matplotlib.pyplot as plt
#np.set_printoptions(threshold=sys.maxsize)

i=Image.open('img/i-300.jpeg')
iar=np.asanyarray(i)
m=iar[:,:,0]
print("Image Showing...")
#plt.imshow(m, interpolation='nearest')
plt.imshow(m, cmap='gray')
plt.show()

0 like 0 dislike
by anonymous Bilge (165k points)
from PIL import Image
import numpy as np
import matplotlib.pyplot as plt
#np.set_printoptions(threshold=sys.maxsize)

i=Image.open('img/i-300.jpeg')
iar=np.asanyarray(i)
m=iar[:,:,0]




methods = [None, 'none', 'nearest', 'bilinear', 'bicubic', 'spline16',
           'spline36', 'hanning', 'hamming', 'hermite', 'kaiser', 'quadric',
           'catrom', 'gaussian', 'bessel', 'mitchell', 'sinc', 'lanczos']


fig, axs = plt.subplots(nrows=3, ncols=6, figsize=(9.3, 6),
                        subplot_kw={'xticks': [], 'yticks': []})

fig.subplots_adjust(left=0.03, right=0.97, hspace=0.3, wspace=0.05)

for ax, interp_method in zip(axs.flat, methods):
    ax.imshow(m, interpolation=interp_method, cmap='viridis')
    ax.set_title(str(interp_method))

plt.tight_layout()
plt.show()
0 like 0 dislike
by anonymous Bilge (165k points)

Tüm color map'leri görmek isterseniz;

import numpy as np
import matplotlib.pyplot as plt

cmaps = [('Perceptually Uniform Sequential', [
            'viridis', 'plasma', 'inferno', 'magma']),
         ('Sequential', [
            'Greys', 'Purples', 'Blues', 'Greens', 'Oranges', 'Reds',
            'YlOrBr', 'YlOrRd', 'OrRd', 'PuRd', 'RdPu', 'BuPu',
            'GnBu', 'PuBu', 'YlGnBu', 'PuBuGn', 'BuGn', 'YlGn']),
         ('Sequential (2)', [
            'binary', 'gist_yarg', 'gist_gray', 'gray', 'bone', 'pink',
            'spring', 'summer', 'autumn', 'winter', 'cool', 'Wistia',
            'hot', 'afmhot', 'gist_heat', 'copper']),
         ('Diverging', [
            'PiYG', 'PRGn', 'BrBG', 'PuOr', 'RdGy', 'RdBu',
            'RdYlBu', 'RdYlGn', 'Spectral', 'coolwarm', 'bwr', 'seismic']),
         ('Qualitative', [
            'Pastel1', 'Pastel2', 'Paired', 'Accent',
            'Dark2', 'Set1', 'Set2', 'Set3',
            'tab10', 'tab20', 'tab20b', 'tab20c']),
         ('Miscellaneous', [
            'flag', 'prism', 'ocean', 'gist_earth', 'terrain', 'gist_stern',
            'gnuplot', 'gnuplot2', 'CMRmap', 'cubehelix', 'brg', 'hsv',
            'gist_rainbow', 'rainbow', 'jet', 'nipy_spectral', 'gist_ncar'])]


nrows = max(len(cmap_list) for cmap_category, cmap_list in cmaps)
gradient = np.linspace(0, 1, 256)
gradient = np.vstack((gradient, gradient))


def plot_color_gradients(cmap_category, cmap_list, nrows):
    fig, axes = plt.subplots(nrows=nrows)
    fig.subplots_adjust(top=0.95, bottom=0.01, left=0.2, right=0.99)
    axes[0].set_title(cmap_category + ' colormaps', fontsize=14)

    for ax, name in zip(axes, cmap_list):
        ax.imshow(gradient, aspect='auto', cmap=plt.get_cmap(name))
        pos = list(ax.get_position().bounds)
        x_text = pos[0] - 0.01
        y_text = pos[1] + pos[3]/2.
        fig.text(x_text, y_text, name, va='center', ha='right', fontsize=10)

    # Turn off *all* ticks & spines, not just the ones with colormaps.
    for ax in axes:
        ax.set_axis_off()


for cmap_category, cmap_list in cmaps:
    plot_color_gradients(cmap_category, cmap_list, nrows)

plt.show()
0 like 0 dislike
by anonymous Bilge (165k points)

show all color maps in python

#!python
from pylab import *
from numpy import outer
rc('text', usetex=False)
a=outer(arange(0,1,0.01),ones(10))
figure(figsize=(10,5))
subplots_adjust(top=0.8,bottom=0.05,left=0.01,right=0.99)
maps=[m for m in cm.datad if not m.endswith("_r")]
maps.sort()
l=len(maps)+1
for i, m in enumerate(maps):
    subplot(1,l,i+1)
    axis("off")
    imshow(a,aspect='auto',cmap=get_cmap(m),origin="lower")
    title(m,rotation=90,fontsize=10)
savefig("colormaps.png",dpi=100,facecolor='gray')
0 like 0 dislike
by anonymous Bilge (165k points)

python subplot ve imshow örneği;

plt.subplot(1, 2, 1), plt.imshow(newmatvar, cmap=plt.cm.Blues)
plt.title('Varyans'), plt.xticks([]), plt.yticks([])
plt.imshow(newmatvar, cmap=plt.cm.Blues)
plt.show()
...