that I haven't updated this in over a year?
Thought not!
Read more...
Sunday, 12 September 2010
Friday, 24 July 2009
A quick Python script to crop and resize photos
The script below was written to resize a stack of images for loading onto a digital photo frame. It may be of some use to others, but as with any scripts available here you use it at your own risk....
Read more...
# Crops and resizes an image for photoframe using PIL
# requires PIL from http://www.pythonware.com/products/pil/index.htm
# Graham Arden, July 2009
from __future__ import division
import os
import shutil
import Image
import Tkinter, tkFileDialog
def resize_image(photoName):
im1 = Image.open(photoName)
imageWidth=im1.size[0]
imageHeight=im1.size[1]
if imageHeight > imageWidth:
path,fi = os.path.split(photoName)
print fi, "is a portrait image, skipped...."
else:
print "Current image is", imageWidth, "pixels wide by", imageHeight, "pixels high"
path,fi = os.path.split(photoName)
saveName = "R_" + fi
newPath = os.path.join(path, saveName)
#Crop the image to convert aspect ratio from 4:3 to 16:9
newImageHeight = int((imageWidth/16) * 9)
topCrop = int((imageHeight-newImageHeight)/2)
bottomCrop= imageHeight-topCrop
box = (0, topCrop, imageWidth, bottomCrop)
croppedImage = im1.crop(box)
# The are the width and height for our final image
width = 800
height = 480
resizedImage = croppedImage.resize((width, height), Image.ANTIALIAS)
print "Resized image is", resizedImage.size[0], "pixels wide by", resizedImage.size[1], "pixels high"
resizedImage.save(newPath)
print "Saved as", newPath
print " "
root = Tkinter.Tk()
root.withdraw()
photoFileNames = tkFileDialog.askopenfilenames(title='Choose the photographs you wish to resize', initialdir="~")
ListLength = len(photoFileNames)
for i in range(0, ListLength):
resize_image(photoFileNames[i])
Read more...
Monday, 20 April 2009
RTFM
Sometimes it really does help to read the manual.....
Today I spent about three hours trying to understand why when I modified the pixel data in a DICOM file and then saved it back under a different file name the original and modified images appeared to be identical. Any other tag I'd edited had changed but the pixel data refused to budge.
I gave up. I banged my head on the desk. Then I read the manual.
Although you edit the pixelArray attribute, any data you edit must be saved back to the pixelData attribute using
....seems obvious now
Read more...
Today I spent about three hours trying to understand why when I modified the pixel data in a DICOM file and then saved it back under a different file name the original and modified images appeared to be identical. Any other tag I'd edited had changed but the pixel data refused to budge.
I gave up. I banged my head on the desk. Then I read the manual.
Although you edit the pixelArray attribute, any data you edit must be saved back to the pixelData attribute using
ds.PixelData = ds.PixelArray.tostring()
....seems obvious now
Read more...
Monday, 6 April 2009
Oh well, not quite.....
Well it looks like I may have to still use MATLAB occasionally. If anyone comes across a Radon transform implementation for Python can they let me know....
Read more...
Read more...
Saturday, 4 April 2009
Cob Records
Just a quick pointer to a great article Adam Walton has written about, what for me is, the best record shop in Wales. I've spent many a happy hour in the place and for me it ranks up pretty close to what was the greatest record shop in England, (although I'll be perfectly honest and admit I haven't been to the latter in years).
I just hope that Amazon and itunes don't mean the end for places like this.
Read more...
I just hope that Amazon and itunes don't mean the end for places like this.
Read more...
Saturday, 28 March 2009
Zotero
If you need a system for storing references then I can strongly recommend Zotero. Its consists of a a Firefox plug-in and a plug-in for either OpenOffice.org (hurrah!) or MS Word (eurgh!).
The 1.5 beta seems very stable and also includes the facility for storing copies of papers if you have access to a webdav server. I'm using it with Amazon's Jungledisk and it works flawlessly, both on Linux at home and XP in work.
Read more...
The 1.5 beta seems very stable and also includes the facility for storing copies of papers if you have access to a webdav server. I'm using it with Amazon's Jungledisk and it works flawlessly, both on Linux at home and XP in work.
Read more...
What's the point?
In case anyone I know happens across this and wonders why I have a blog, well, why not?
I find it useful, when I'm working on something, to just write it down. Sometimes it may help, sometimes it will be utter nonsense, occasionally I may actually come across something useful. (Well that's the hope anyway).
If nothing else it may occasionally be useful if I'm trying to remember why I did something.
Read more...
I find it useful, when I'm working on something, to just write it down. Sometimes it may help, sometimes it will be utter nonsense, occasionally I may actually come across something useful. (Well that's the hope anyway).
If nothing else it may occasionally be useful if I'm trying to remember why I did something.
Read more...
Subscribe to:
Posts (Atom)
