Re: cropping a random part of an image
Hi Peter, Hi Robin, thanks for your help, and especially for the code ;) @Peter: thanks for the links, I know, it is always better to write the code than to copy and paste! @Robin: the question, iḿ trying to answer is, if good pictures, in this case portraits, also have good "Parts", so if the beauty of a picture can be found in its crops, too. In the and it is for a deep CNN and I hope it will work! Thanks again! Steffen -- https://mail.python.org/mailman/listinfo/python-list
Re: cropping a random part of an image
Hi Robin, I tried to understand and run your code, and I get the Error: "File "Rand_Crop.py", line 15, in with Image.open(os.path.join(INPATH, file)) as im: File "/usr/lib/python2.7/dist-packages/PIL/Image.py", line 528, in __getattr__ raise AttributeError(name) AttributeError: __exit__" I looked up the Image.py and don't know, why the Name could not be read out. If i print the names of the images out, before the first "for" everything is fine, but it dosen't work after line 15. I try to figure this out, but if someone has a hint, I would be happy! Steffen -- https://mail.python.org/mailman/listinfo/python-list
Re: cropping a random part of an image
Ok, did it :)
import random, os, time
from PIL import Image
INPATH = ('/home/sdrewes/Desktop/Portaits/Bilder/Test/')
OUTPATH = ('/home/sdrewes/Desktop/Portaits/Bilder/Gut_Crop/')
dx = dy = 228
tilesPerImage = 100
files = os.listdir(INPATH)
numOfImages = len(files)
print(files)
t = time.time()
for file in files:
im = Image.open(INPATH+file)
for i in range(1, tilesPerImage+1):
newname = file.replace('.', '_{:03d}.'.format(i))
w, h = im.size
x = random.randint(0, w-dx-1)
y = random.randint(0, h-dy-1)
print("Cropping {}: {},{} -> {},{}".format(file, x,y, x+dx,
y+dy))
im.crop((x,y, x+dx, y+dy))\
.save(os.path.join(OUTPATH, newname))
t = time.time()-t
print("Done {} images in {:.2f}s".format(numOfImages, t))
print("({:.1f} images per second)".format(numOfImages/t))
print("({:.1f} tiles per second)".format(tilesPerImage*numOfImages/t))
--
https://mail.python.org/mailman/listinfo/python-list
Re: cropping a random part of an image
Ok, now it works for me!
Thanks again!
import random, os, time
from PIL import Image
INPATH = ('/home/.../Start/')
OUTPATH = ('/home/.../Ziel/')
dx = dy = 228
tilesPerImage = 25
files = os.listdir(INPATH)
numOfImages = len(files)
print(files)
t = time.time()
for file in files:
im = Image.open(INPATH+file)
for i in range(1, tilesPerImage+1):
newname = file.replace('.', '_{:03d}.'.format(i))
w, h = im.size
x = random.randint(0, w-dx-1)
y = random.randint(0, h-dy-1)
print("Cropping {}: {},{} -> {},{}".format(file, x,y, x+dx,
y+dy))
im.crop((x,y, x+dx, y+dy))\
.save(os.path.join(OUTPATH, newname))
t = time.time()-t
print("Done {} images in {:.2f}s".format(numOfImages, t))
print("({:.1f} images per second)".format(numOfImages/t))
print("({:.1f} tiles per second)".format(tilesPerImage*numOfImages/t))
--
https://mail.python.org/mailman/listinfo/python-list
Saving Consol outputs in a python script
Hello, I'm new to python and have a Question. I'm running a c++ file with a python script like: import os import subprocess subprocess.call(["~/caffe/build/examples/cpp_classification/classification", "deploy.prototxt", "this.caffemodel", "mean.binaryproto", "labels.txt", "Bild2.jpg"]) and it runes fine. On the console it gives me the output: ~/Desktop/Downloader/Sym+$ python Run_C.py -- Prediction for Bild2.jpg -- 0.9753 - "Class 1" 0.0247 - "Class 2" What I need are the 2 values for the 2 classes saved in a variable in the .py script, so that I can write them into a text file. Would be super nice if someone could help me! have a nice day! Steffen -- https://mail.python.org/mailman/listinfo/python-list
cropping a random part of an image
Hi, I'm new to python and I have 30.000 pictures. I need to crop, let's say 100, parts of 256x256, randomly out of every picture. I cant find an answer in the net, would be nice if someone could help me out! Thanks! Steffen -- https://mail.python.org/mailman/listinfo/python-list
