I'm trying to implement image processing s/w that requires me to implement an image enhancement module that performs various operations like Color, Contrast, Brightness, Sharpness manipulation on the same image. I've implemented a module but it works on the same (original) image and changes done are not reflected.

Please help.

#enh.py
# this script creates four windows containing an image and a slider.
# drag the slider to modify the image.
#

from Tkinter import *
from PIL import Image, ImageTk, ImageEnhance
import sys
import histogram


#
# enhancer widget

class Enhance(Frame):
    def __init__(self, master, name, enhancer, lo, hi):
        Frame.__init__(self, master)


        self.enhancer = enhancer(image)

        self.update('1.0') # normalize

        s = Scale(self, label=name, orient=HORIZONTAL,
                  from_=lo, to=hi, resolution=0.01,
                  command=self.update)

        s.set(self.value)
        s.grid(row=0,column=0)



    def update(self, value):
        self.value = eval(value)
        tkim.paste(self.enhancer.enhance(self.value))
        self.enhancer.enhance(self.value).save("tmp.jpg")
        histogram.make(self,"tmp.jpg")
        self.image= Image.open('tmp.jpg')


    def save_op():
        op.save("new.jpg")

#
# main

call statements-
nh.image = Image.open(filename)
enh.image = enh.image.resize((700,500),Image.ANTIALIAS)
enh.tkim = ImageTk.PhotoImage(enh.image.mode,enh.image.size)
enh.Enhance(root, "Color", ImageEnhance.Color, 0.0, 4.0).grid(row=3,column=0)
enh.Enhance(root, "Sharpness", ImageEnhance.Sharpness, -2.0, 2.0).grid(row=3,column=1)
enh.Enhance(root, "Brightness", ImageEnhance.Brightness, -1.0, 3.0).grid(row=4,column=0)
enh.Enhance(root, "Contrast", ImageEnhance.Contrast, -1.0, 3.0).grid(row=4,column=1)

Recommended Answers

All 3 Replies

Your code does not make any kind of sense, what image at line 20? What enhancer at same line?

the "image" as been initialized via a different script. It is a filename(path) that the user selects.

enh.image = Image.open(filename)
enh.image = enh.image.resize((700,500),Image.ANTIALIAS)
enh.tkim = ImageTk.PhotoImage(enh.image.mode,enh.image.size)
enh.Enhance(root, "Color", ImageEnhance.Color, 0.0, 4.0).grid(row=3,column=0)
enh.Enhance(root, "Sharpness", ImageEnhance.Sharpness, -2.0, 2.0).grid(row=3,column=1)
enh.Enhance(root, "Brightness", ImageEnhance.Brightness, -1.0, 3.0).grid(row=4,column=0)
enh.Enhance(root, "Contrast", ImageEnhance.Contrast, -1.0, 3.0).grid(row=4,column=1)

All I can think of is making this "image" static and volatile(as in JAVA) but as I'm new here, i dont know how to implement both. Also python does not support static variables. Please help me.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.