I have a Python Script, which has to import very large image-files (.tiff, ca. 3GB).
Is there a way to display a progressbar in the command line?
I haven't found a way to measure the progress of an import except for text files.
My current function looks like this:
from skimage import io
def import_tiff(filename):
im = io.imread(filename)
return im
Thank you very much!
Related
Hi so i have code which gives the answer in form of speech. I am using this code:
audio.save("audio.wav")
sound_file = '/content/audio.wav'
Audio(sound_file, autoplay=True)
Now the code plays file all well but if I play in a separate cell. But if I put this code in between my code, it doesn't work. Any ideas?
Wrap it in display():
from IPython.display import Audio, display
display(Audio(sound_file, autoplay=True))
Use this:
from IPython.display import Audio
wn = Audio('path_to_wav_file', autoplay=True)
display(wn)
I'm working with this custom Py visual in PowerBI. Unfortunately, Power BI has some Python code leading my code that pre-defines the image size (5.55555555555556,4.16666666666667).
The result is a small image surrounded by a lot of empty space:
Is there any way I can redefine the size of the image, even though I cannot modify the leading code?
Any other suggestions are welcome,
Thanks!
# Prolog - Auto Generated #
import os, uuid, matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot
import pandas
os.chdir(u'C:/Users/USER/PythonEditorWrapper_443a6d71-c4cc-4e62-ac6f-2dad3eeace3d')
dataset = pandas.read_csv('input_df_d2b6d8be-2212-4ece-902c-f85219eff22b.csv')
matplotlib.pyplot.figure(figsize=(5.55555555555556,4.16666666666667), dpi=72)
matplotlib.pyplot.show = lambda args=None,kw=None: matplotlib.pyplot.savefig(str(uuid.uuid1()))
#My code starts here, I cannot modify anything above this line.
#I wish I could add a line here to redefine figsize=(5.55555555555556,4.16666666666667)
from matplotlib import pyplot as plt
plt.figure(figsize=(15,20))
try this
Is there a way to use and plot with opencv2 with ipython notebook?
I am fairly new to python image analysis. I decided to go with the notebook work flow to make nice record as I process and it has been working out quite well using matplotlib/pylab to plot things.
An initial hurdle I had was how to plot things within the notebook. Easy, just use magic:
%matplotlib inline
Later, I wanted to perform manipulations with interactive plots but plotting in a dedicated window would always freeze. Fine, I learnt again that you need to use magic. Instead of just importing the modules:
%pylab
Now I have moved onto working with opencv. I am now back to the same problem, where I either want to plot inline or use dedicated, interactive windows depending on the task at hand. Is there similar magic to use? Is there another way to get things working? Or am I stuck and need to just go back to running a program from IDLE?
As a side note: I know that opencv has installed correctly. Firstly, because I got no errors either installing or importing the cv2 module. Secondly, because I can read in images with cv2 and then plot them with something else.
This is my empty template:
import cv2
import matplotlib.pyplot as plt
import numpy as np
import sys
%matplotlib inline
im = cv2.imread('IMG_FILENAME',0)
h,w = im.shape[:2]
print(im.shape)
plt.imshow(im,cmap='gray')
plt.show()
See online sample
For a Jupyter notebook running on Python 3.5 I had to modify this to:
import io
import cv2
import numpy as np
from IPython.display import clear_output, Image, display
import PIL.Image
def showarray(a, fmt='jpeg'):
a = np.uint8(np.clip(a, 0, 255))
f = io.BytesIO()
PIL.Image.fromarray(a).save(f, fmt)
display(Image(data=f.getvalue()))
There is also that little function that was used into the Google Deepdream Notebook:
import cv2
import numpy as np
from IPython.display import clear_output, Image, display
from cStringIO import StringIO
import PIL.Image
def showarray(a, fmt='jpeg'):
a = np.uint8(np.clip(a, 0, 255))
f = StringIO()
PIL.Image.fromarray(a).save(f, fmt)
display(Image(data=f.getvalue()))
Then you can do :
img = cv2.imread("an_image.jpg")
And simply :
showarray(img)
Each time you need to render the image in a cell
I'm trying to see images as generated by the Python Imaging Library. Using the following snippet returns after displaying the image in a separate process. Is there a way to show images and have the python script block until I close the window?
from PIL import Image
...
img = Image.open(...)
img.show()
I could use a GUI library like Qt to achieve this. I don't want to add that just to view an image.
An indirect way to achieve a blocking call is to show a PIL image in matplotlib:
import matplotlib.pyplot as plt
import numpy as np
import PIL
img = PIL.Image.open("image.jpg")
plt.imshow(np.asarray(img))
plt.show() # Default is a blocking call
Pillow explicitly starts its Mac and Unix Viewers in the background. Fortunately, Pillow also exposes a way to register custom viewers so you can override this behaviour.
I use feh personally:
import os
from PIL ImageShow
class FehViewer(ImageShow.UnixViewer):
def show_file(self, filename, **options):
os.system('feh %s' % filename)
return 1
ImageShow.register(FehViewer, order=-1)
[...]
A simple UI window using tk can accomplish this:
from PIL import Image, ImageTk
from tkinter import Tk, Label, BOTH
from tkinter.ttk import Frame, Style
class Example(Frame, object):
def __init__(self, parent):
Frame.__init__(self, parent)
self.pack(fill=BOTH, expand=1)
label1 = Label(self)
label1.photo= ImageTk.PhotoImage(Image.open(r"myImage"))
label1.config(image=label1.photo)
label1.pack(fill=BOTH, expand=1)
parent.mainloop()
Example(Tk())
Note: the code is in python 3, for python 2 the imports would be slightly different:
from Tkinter import Tk, Label, BOTH
from ttk import Frame, Style
I have currently written an python script that takes input from the user's video camera with the following code:
import numpy as np
import cv2
import cv
import datetime
import math
import time
import os
cap = cv2.VideoCapture(0)
def init():
ret, imgBase = cap.read()
print(type(imgBase))`
The above code is completely functional and it does get input from the user. However, instead of getting input from the user's web cam, I want to get input from user's screen. I need something like cap = cv2.ScreenCapture(0) I understand that that doesn't work, but I need something that does a similar function so I can read and capture an image from the user screen. In essence, I need to get a screenshot of the monitor/user's screen.
Only works on Mac:
import os
os.system('screencapture out.jpg')
You can read the screenshot into memory using default python functions.
For further info type man screencapture in a terminal or check this link: https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/screencapture.1.html.