Пример #1
0
    def __init__(self, parent=None):

        Qt.QMainWindow.__init__(self, parent)
        self.frame = Qt.QFrame()
        self.layout = Qt.QVBoxLayout()
        self.vtkWidget = QVTKRenderWindowInteractor(self.frame)

        # Create vedo renderer and add objects and callbacks
        self.vp = Plotter(qtWidget=self.vtkWidget)
        self.cbid = self.vp.addCallback("key press", self.onKeypress)
        self.imgActor = Picture(
            "https://icatcare.org/app/uploads/2018/07/Helping-your-new-cat-or-kitten-settle-in-1.png"
        )
        self.text2d = Text2D("Use slider to change contrast")

        self.slider = Qt.QSlider(1)
        self.slider.valueChanged.connect(self.onSlider)
        self.layout.addWidget(self.vtkWidget)
        self.layout.addWidget(self.slider)

        self.frame.setLayout(self.layout)
        self.setCentralWidget(self.frame)
        self.vp.show(self.imgActor, self.text2d,
                     mode='image')  # build the vedo rendering
        self.show()  # show the Qt Window
Пример #2
0
class MainWindow(Qt.QMainWindow):
    def __init__(self, parent=None):

        Qt.QMainWindow.__init__(self, parent)
        self.frame = Qt.QFrame()
        self.layout = Qt.QVBoxLayout()
        self.vtkWidget = QVTKRenderWindowInteractor(self.frame)

        # Create vedo renderer and add objects and callbacks
        self.vp = Plotter(qtWidget=self.vtkWidget)
        self.cbid = self.vp.addCallback("key press", self.onKeypress)
        self.imgActor = Picture(
            "https://icatcare.org/app/uploads/2018/07/Helping-your-new-cat-or-kitten-settle-in-1.png"
        )
        self.text2d = Text2D("Use slider to change contrast")

        self.slider = Qt.QSlider(1)
        self.slider.valueChanged.connect(self.onSlider)
        self.layout.addWidget(self.vtkWidget)
        self.layout.addWidget(self.slider)

        self.frame.setLayout(self.layout)
        self.setCentralWidget(self.frame)
        self.vp.show(self.imgActor, self.text2d,
                     mode='image')  # build the vedo rendering
        self.show()  # show the Qt Window

    def onSlider(self, value):
        self.imgActor.window(value * 10)  # change image contrast
        self.text2d.text(f"window level is now: {value*10}")
        self.vp.render()

    def onKeypress(self, evt):
        printc("You have pressed key:", evt.keyPressed, c='b')
        if evt.keyPressed == 'q':
            self.vp.close()
            self.vtkWidget.close()
            exit()

    def onClose(self):
        self.vtkWidget.close()
Пример #3
0
# 2D Fast Fourier Transform of a picture
from vedo import Picture, show

# url = 'https://comps.canstockphoto.com/a-capital-silhouette-stock-illustrations_csp31110154.jpg'
url = 'https://vedo.embl.es/examples/data/images/dog.jpg'

pic = Picture(url).resize(
    [200, None])  # resize so that x has 200 pixels, but keep y aspect-ratio
picfft = pic.fft(logscale=12)
picfft = picfft.tomesh().cmap('Set1', "RGBA").addScalarBar(
    "12\dotlog(fft)")  # optional step

show(
    [
        [pic, f"Original image\n{url[-40:]}"],
        [picfft, "2D Fast Fourier Transform"],
        [pic.fft(mode='complex').rfft(), "Reversed FFT"],
    ],
    N=3,
    bg='gray7',
    axes=1,
)
Пример #4
0
"""Example plot of 2 images containing an
alpha channel for modulating the opacity"""
#Credits: https://github.com/ilorevilo
from vedo import Picture, show
import numpy as np

rgbaimage1 = np.random.rand(50, 50, 4) * 255
alpharamp = np.linspace(0, 255, 50).astype(int)
rgbaimage1[:, :, 3] = alpharamp
rgbaimage2 = np.random.rand(50, 50, 4) * 255
rgbaimage2[:, :, 3] = alpharamp[::-1]

p1 = Picture(rgbaimage1)

p2 = Picture(rgbaimage2).z(12)

show(p1, p2, __doc__, axes=7, viewup="z")
Пример #5
0
# Transform a picture into a mesh
from vedo import Picture, dataurl, show
import numpy as np

pic = Picture(dataurl + "images/dog.jpg").smooth(5)
msh = pic.tomesh()  # make a quad-mesh out of it

# build a scalar array with intensities
rgb = msh.pointdata["RGBA"]
intensity = np.sum(rgb, axis=1)
intensityz = np.zeros_like(rgb)
intensityz[:, 2] = intensity / 10

# set the new vertex points
pts = msh.points() + intensityz
msh.points(pts)

# more cosmetics
msh.triangulate().smooth()
msh.lighting("default").lineWidth(0.1)
msh.cmap("bone", "RGBA").addScalarBar()

msht = pic.clone().threshold(100).lineWidth(0)

show([[pic, "A normal jpg image.."], [msh, "..becomes a polygonal Mesh"],
      [msht, "Thresholding also generates a Mesh"]],
     N=3,
     axes=1,
     zoom=5,
     elevation=-20,
     bg='black').close()
Пример #6
0
"""Example plot of 2 images containing an
alpha channel for modulating the opacity"""
#Credits: https://github.com/ilorevilo
from vedo import Picture, show
import numpy as np

rgbaimage1 = np.random.rand(50, 50, 4) * 255
alpharamp = np.linspace(0, 255, 50).astype(int)
rgbaimage1[:, :, 3] = alpharamp
rgbaimage2 = np.random.rand(50, 50, 4) * 255
rgbaimage2[:, :, 3] = alpharamp[::-1]

p1 = Picture(rgbaimage1)

p2 = Picture(rgbaimage2).z(12)

show(p1, p2, __doc__, axes=7, viewup="z").close()

# Second example: a b&w image from a numpy array
img = np.zeros([512, 512])
img[0:256, 0:256] = 0
img[0:256, 256:] = 64
img[256:, 0:256] = 128
img[256:, 256:] = 255
img = img.transpose(1, 0)

pict = Picture(img)

show(pict, mode="image", bg=(0.4, 0.5, 0.6), axes=1).close()
Пример #7
0
from vedo import Picture, show, settings
from vedo.pyplot import histogram
import numpy as np

settings.defaultFont = "Theemim"

pic = Picture(
    "https://aws1.discourse-cdn.com/business4/uploads/imagej/original/3X/5/8/58468da123203f6056ca786adf159064db47aefa.jpeg"
)
msh = pic.tomesh()  # convert it to a quad-mesh
rgb = msh.pointdata["RGBA"]  # numpy array

tot = np.sum(rgb, axis=1) + 0.1  # add 0.1 to avoid divide by zero
ratio_g = rgb[:, 1] / tot
ratio_r = rgb[:, 0] / tot

ids_r = np.where(ratio_r > 0.38)  # threshold to find the red vase
ids_g = np.where(ratio_g > 0.36)  # threshold for grass
ids_w = np.where(tot > 240 * 3)  # threshold to identify white areas

data_g = np.zeros(msh.N())
data_r = np.zeros(msh.N())
data_w = np.zeros(msh.N())
data_r[ids_r] = 1.0
data_g[ids_g] = 1.0
data_w[ids_w] = 1.0

ngreen = len(ids_g[0])
total = len(rgb) - len(ids_r[0]) - len(ids_w[0])
gvalue = int(ngreen / total * 100 + 0.5)
Пример #8
0
"""Earthquakes of magnitude 2.5+ in the past 30 days
areas are proportional to energy release
[hover mouse to get more info]"""
import pandas, numpy as np
from vedo import download, Picture, Polygon, ProgressBar, colorMap, Plotter, Text2D

num = 50  # nr of earthquakes to be visualized to define a time window
path = download("https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/2.5_month.csv")
usecols = ['time','place','latitude','longitude','depth','mag']
data = pandas.read_csv(path, usecols=usecols)[usecols][::-1].reset_index(drop=True) # reverse list

pic = Picture("https://eoimages.gsfc.nasa.gov/images/imagerecords/147000/147190/eo_base_2020_clean_3600x1800.png")
pic.pickable(False).level(185).window(120)  # add some contrast to the original image
scale = [pic.shape[0]/2, pic.shape[1]/2, 1]

def GeoCircle(lat, lon, r, res=50):
    coords = []
    sinr, cosr = np.sin(r), np.cos(r)
    sinlat, coslat = np.sin(lat), np.cos(lat)
    for phi in np.linspace(0, 2*np.pi, num=res, endpoint=False):
        clat = np.arcsin(sinlat * cosr + coslat * sinr * np.cos(phi))
        clng = lon + np.arctan2(np.sin(phi) * sinr * coslat, cosr - sinlat * np.sin(clat))
        coords.append([clng/np.pi + 1, clat*2/np.pi + 1, 0])
    return Polygon(nsides=res).points(coords)  # warp polygon points to match geo projection


centers = []
pb = ProgressBar(0, len(data))
for i, d in data.iterrows():
    pb.print("Parsing USGS data..")
    M = d['mag']                                       # earthquake estimated magnitude
Пример #9
0
"""Probe image intensities along a set of radii"""
from vedo import Picture, dataurl, Circle, Lines, show
from vedo.pyplot import plot
import numpy as np

pic = Picture(dataurl + 'images/spheroid.jpg')
cpt = [580, 600, 0]
circle = Circle(cpt, r=500, res=36).wireframe()

pts = circle.points()  # 3d coords of the points of the circle
centers = np.zeros_like(pts) + cpt  # create the same amount of center coords
lines = Lines(centers, pts,
              res=50)  # create Lines with 50 pts of resolution each

msh = pic.tomesh()  # transform the picture into a quad mesh
lines.interpolateDataFrom(msh, N=3)  # interpolate all msh data onto the lines
rgb = lines.pointdata['RGBA']  # extract the rgb intensities
intensities = np.sum(rgb,
                     axis=1)  # sum the rgb values into one single intensty
intensities_ray = np.split(intensities,
                           36)  # split array so we can index any radius
mean_intensity = np.mean(intensities_ray,
                         axis=0)  # compute the average intensity

# add some optional plotting here:
plt = plot(mean_intensity,
           lc='black',
           lw=5,
           spline=True,
           xtitle='radial distance',
           ytitle='intensity',
Пример #10
0
"""Normal jpg/png pictures can be loaded,
cropped, rotated and positioned in 3D."""
from vedo import Plotter, Picture, dataurl

plt = Plotter(axes=7)

pic = Picture(dataurl + "images/dog.jpg")

for i in range(5):
    p = pic.clone()
    p.crop(bottom=0.20)  # crop 20% from bottom
    p.scale(1 - i / 10.0).rotateX(20 * i).z(30 * i)
    p.alpha(0.8)
    plt += p

plt += __doc__
plt.show()
plt.close()