Hi,
I'm using PIL to tint and composite images together. Here's how I'm
currently tinting images, it's really slow and I know there's got to
be a better way:
def TintImage( im, tintColor ):
tint = (tintColor[0]/255.0, tintColor[1]/255.0, tintColor[2]/255.0,
tintColor[3]/255.0)
pix = im.load()
for x in xrange( im.size[0] ):
for y in xrange( im.size[1] ):
c = pix[x,y]
pix[x,y] = (int(c[0]*tint[0]), int(c[1]*tint[1]),
int(c[2]*tint[2]), c[3])
I thought maybe there's a way to do it using the transform method, but
I haven't figure it out yet. Anyone?
Thanks
-Dan 2 7769
Dan Moskowitz wrote:
I'm using PIL to tint and composite images together. Here's how I'm
currently tinting images, it's really slow and I know there's got to
be a better way:
def TintImage( im, tintColor ):
tint = (tintColor[0]/255.0, tintColor[1]/255.0, tintColor[2]/255.0,
tintColor[3]/255.0)
pix = im.load()
for x in xrange( im.size[0] ):
for y in xrange( im.size[1] ):
c = pix[x,y]
pix[x,y] = (int(c[0]*tint[0]), int(c[1]*tint[1]),
int(c[2]*tint[2]), c[3])
I thought maybe there's a way to do it using the transform method, but
I haven't figure it out yet. Anyone?
Too lazy to read the manual? How about
def tint_image(im, color):
color_map = []
for component in color:
color_map.exten d(int(component/255.0*i) for i in range(256))
return im.point(color_ map)
Peter
On Thu, 06 Nov 2008 13:08:59 -0800, Dan Moskowitz wrote:
I'm using PIL to tint and composite images together. Here's how I'm
currently tinting images, it's really slow and I know there's got to be
a better way:
def TintImage( im, tintColor ):
tint = (tintColor[0]/255.0, tintColor[1]/255.0, tintColor
[2]/255.0,
tintColor[3]/255.0)
pix = im.load()
for x in xrange( im.size[0] ):
for y in xrange( im.size[1] ):
c = pix[x,y]
pix[x,y] = (int(c[0]*tint[0]), int(c[1]*tint[1]),
int(c[2]*tint[2]), c[3])
I thought maybe there's a way to do it using the transform method, but I
haven't figure it out yet. Anyone?
from PIL import Image, ImageChops
def tint_image(imag e, tint_color):
return ImageChops.mult iply(image,
Image.new('RGB' , image.size, tint_color))
Ciao,
Marc 'BlackJack' Rintsch This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Patrick |
last post by:
Hello all!
I am using a BufferedImage object to build an image from scratch.
I want it to be a grayscale image with only 8bits of color. I have
the color information as a byte, saved in variable name byte4. I have
written the following code:
First, thePanorama is defined as:
new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
Then I loop through like follows:
|
by: Thomas |
last post by:
Hi all,
Is there a faster way to read image dimensions other than something
like:
ImageOrig = System.Drawing.Image.FromFile(Filepath);
ImageOrigHeight = ImageOrig.Height;
ImageOrigWidth = ImageOrig.Width;
The problem is this operation takes quite a bit of time to complete
(100+ ms).
|
by: James dean |
last post by:
The following code is the current method i have for converting an image
to Base64.Is this the most efficient way to convert an image to base64
or are there others. The Image class's Save method is slow here and i am
wondering if i can do it some other way to make it faster.....Any ideas
public string ImageToBase64String(Image imageData ImageFormat format)
{
string base64;
MemoryStream memory = new MemoryStream();
imageData.Save(memory,...
|
by: johnb41 |
last post by:
My app has an image (black/white tiff) displayed in a picturebox
(scanned text document). I need the user to be able to draw either
white or black rectangles on it. (to hide/cover up sensitive
information, like credit card numbers).
I can do this by loading the file into a graphics object, and then
using the graphics object's methods to do the drawing. The modified
file is then re-displayed on the screen. (by the way, I am using the...
|
by: jordi_ramis |
last post by:
Hi,
I'm currently using image.fromfile to load jpg images in my
application. I've noted that this procedure is very slow compared to
some aplications I have seen. Is there any way to load a jpeg image
into an image or bitmap object faster that image.fromfile?. Prefereably
one method or component that is free.
Thanks a lot for your help.
| |
by: Chaos |
last post by:
As my first attempt to loop through every pixel of an image, I used
for thisY in range(0, thisHeight):
for thisX in range(0, thisWidth):
#Actions here for Pixel thisX, thisY
But it takes 450-1000 milliseconds
I want speeds less than 10 milliseconds
|
by: Speed |
last post by:
Hi,
Could you please tell me what is the simplest code to read a 8-bit
grayscale JPEG using C++?
Thanks a ton,
Speed.
|
by: ShadowLocke |
last post by:
How can I tint one color with another color? i.e. say i have a Color.LightSkyBlue
(135,206,250) i want to tint it with Color.Green(0,128, 0)
Whats the math behind it?
|
by: Airslash |
last post by:
Hello,
been a while since I visited bytes.com, but I have an issue with GDIplus...
I'm currently developing on/for a Windows Server 2003 system and I'm running a Benchmark to find the fastest and most performent way of resizing a jpg file from MegaPixel format to 640 * 480 size.
Gdiplus currently offers the fastest way for me with a result of 3ms / resize.
I am however recieving random Access Violations exceptions and the small tool...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |