Straight line detection
Does anyone know of a simple implementation of a straight line detection algorithm something like hough or anything simpler.So something like if we have a 2D arary of pixel elements representing a particular Image. How can we identify lines in this Image. for example: ary = [[1,1,1,1,1], [1,1,0,0,0], [1,0,1,0,0], [1,0,0,1,0], [1,0,0,0,1]] So if 'ary' represents pxl of an image which has a horizontal line(row 0),a vertical line(col 0) and a diagonal line(diagonal of ary). then basically I want identify any horizontal or vertical or diagonal line anywhere in the pxl array. Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Pixel Manipulations
Does anyone know of a simple implementation for detecting straight line .So something like if we have a 2D arary of pixel elements representing a particular Image. How can we identify lines in this Image. for example: ary = [[1,1,1,1,1], [1,1,0,0,0], [1,0,1,0,0], [1,0,0,1,0], [1,0,0,0,1]] So if 'ary' represents pxl of an image which has a horizontal line(row 0),a vertical line(col 0) and a diagonal line(diagonal of ary). then basically I want identify any horizontal or vertical or diagonal line anywhere in the pxl array and return true if its composed of only lines else false... Thanks. -- http://mail.python.org/mailman/listinfo/python-list
File compare
I have two files file1 in format 'AA' 1 T T 'AB' 1 T F file2 same as file1 'AA' 1 T T 'AB' 1 T T Also the compare should be based on id. So it should look for line starting with id 'AA' (for example) and then match the line so if in second case. so this is what I am looking for: 1. read both files. 2. read id of first line in file1 check if it matches with the same id in file2. 3. repeat step 2 for all lines in file1. 4. return a percent of success to failure. ie if one line matches and one lines does'nt then return 0.5 or 50% I wrote a boolean version ..as a start def getdata(f): try: f1 = open(f,'r') data=[] for eachline in f1.readlines(): data.append(re.split("", re.sub('\n','',strip(re.split('\s\s+',eachline)[0] return data except IOError: raise("Invalid File Input") if __name__=='__main__': data1 = getdata('file1') data2 = getdata('file2') if data1 == data2: print "True" else: print "False" hope I am clear... -- http://mail.python.org/mailman/listinfo/python-list
Re: File compare
Note that the code i wrote wont do the compare based on id which i am looking for..it just does a direct file to file compare.. -- http://mail.python.org/mailman/listinfo/python-list
Re: File compare
Not for homework. But anyway thanks much... -- http://mail.python.org/mailman/listinfo/python-list
Re: File compare
but what if case 1: no.of keys in f1 > f2 and case2: no.of keys in f1 < f2. Should'nt we get 1.1 if case 1 and 0.9 if case 2?? it errors of with a keyerror.? -- http://mail.python.org/mailman/listinfo/python-list
Function to execute only once
Hi if I have a function called tmp=0 def execute(): tmp = tmp+1 return tmp also I have def func1(): execute() and def func2(): execute() now I want execute() function to get executed only once. That is the first time it is accessed. so taht when funcc2 access the execute fn it should have same values as when it is called from func1. -- http://mail.python.org/mailman/listinfo/python-list
Tricky Areas in Python
What possible tricky areas/questions could be asked in Python based Technical Interviews? -- http://mail.python.org/mailman/listinfo/python-list
Re: Tricky Areas in Python
hmm Thats one thing. Also I was thinking of something like benefites of python over other languages. Probably that coould be one ? -- http://mail.python.org/mailman/listinfo/python-list
Add attribute using pyxml
How do I add a new attribute to the existing xml Document tree??? -- http://mail.python.org/mailman/listinfo/python-list
calculate system disk space
how can we compute the current system disk space using a python script.? any ideas or have anyone tried this.. -- http://mail.python.org/mailman/listinfo/python-list
Re: calculate system disk space
I am looking for unix.the recipe is windows specific!! -- http://mail.python.org/mailman/listinfo/python-list
Line Removal strategy
Hi I am looking for a simple algorithm for removing straight lines in a given Image using something like an PIL or simpler. -- http://mail.python.org/mailman/listinfo/python-list
Grouping lists
If I have a list say lst = [1,1,1,1,3,5,1,1,1,1,7,7,7] I want to group the list so that it returns groups such as [(0,3),4,5,(6,9),(10,12)]. which defines the regions which are similar. Thanks, -- http://mail.python.org/mailman/listinfo/python-list
Re: Grouping lists
hmm thanks for that..but kind of not sure how this groupby works.. also if I want to group elements with one value apart how would this change.Should this change in groupby part or in the loop? something like... lst = [1,1,2,1,3,5,1,1,1,1,2,7,7] returns (0,3),4,5,(6,10),(11,12) so its something like if there is 1,1,2 then the grouping is done.. I am asking this as I could not quit follow what exactly groupby does.. Also if someone could explain me what exactly this groupby is doing that would be helpful. Thanks again. -- http://mail.python.org/mailman/listinfo/python-list
Line Scan and Removal
i I need some help on some problem I am trying to think of. are there any algorithms available to do the following If not, any ideas?: I would like to Identify any lines of any orientation and width in an Image and remove them from the Image. Basically I would like to scan the entire Image for lines and remove them. so for example if I have an Image with a circle, a triangle and a line. Then my resultant Image should only have a circle. Can some one help me think through this process... Thanks -- http://mail.python.org/mailman/listinfo/python-list
understanding mod_python
Hi I'm trying to learn mod python and need some one to explain how to do http redirection(302) with an example code -- http://mail.python.org/mailman/listinfo/python-list
Performance Issues please help
I was testing this piece of code and it takes about 24-30 seconds to do a look up on a list(m) of size 1000x1000 m -> list of size 1000x1000 import time print time.ctime() box = {} for r,row in enumerate(m): for c,e in enumerate(row): if box.has_key(e): params = box[e] box[e] = ( min(c, params[0]), min(r, params[1]), max(c, params[2]), max(r, params[3] ) ) else: box[e] = [c, r, c, r] print time.ctime() Can some one tell me what exactly is taking more time here. Is it because I am using dictionaries or what is the problem. Can some one help me improve this .Is there a better way to write this. -- http://mail.python.org/mailman/listinfo/python-list
Re: Performance Issues please help
>Info req'd for discussing algorithm changes: >1. How much free memory do you have? - Memory is not a problem but I am working on some timing constraints.Thats is the reason I am a bit concerned abt these 30 seconds > 2. What can you tell us about the distribution of "e"? - the distribution of e is not fixed.It changes based on what comes first in the scan of the list. > 3. Is "m" a rectangle, or are the rows of variable length? - m is not a restnagle .its of varied dimensions. > 4. Do you have control over "m" i.e. are you stuck with that data structure, or can we design a different one? -I can use 'm' as an array or a list. Other than that I am stuck. I am suspecious abput dictionary approach here. Is this slower than if i do it with arrays or lists with index of array as my key ? -- http://mail.python.org/mailman/listinfo/python-list
Re: Performance Issues please help
Yep that improved the speed by about 50% now it takes about 10 secs instead of 24 seconds..Thanks much. I guess that is the best we could do right.It would be really helpful if I could get it less than 5 seconds. Any suggestions on that?? -- http://mail.python.org/mailman/listinfo/python-list
Tiff Image Reader/writer
Hi I am looking for a simple tiff Image reader/writer in python.Can anyone point me to the right one. -- http://mail.python.org/mailman/listinfo/python-list
Re: Tiff Image Reader/writer
Is there any package out there which handles Tiff Images other than PIL or ImageMagic . -- http://mail.python.org/mailman/listinfo/python-list
Re: Tiff Image Reader/writer
nothing fancy. I just want to be able to read a tiff image, get pixel values, write back to a tiff file. -- http://mail.python.org/mailman/listinfo/python-list
Re: Tiff Image Reader/writer
One reason why I don't want to use PIL is it seems very slow for tiff images of very large sizes(2400x4800). So I am looking for a better tool than does the right job faster. -- http://mail.python.org/mailman/listinfo/python-list
Re: Tiff Image Reader/writer
When i try this i get this error: import Image >>> im = Image.open('image.tif') >>> im.getpixel((10,19)) Traceback (most recent call last): File "", line 1, in ? File "Image.py", line 858, in getpixel self.load() File "/usr/local/lib/python2.4/site-packages/PIL/ImageFile.py", line 180, in load d = Image._getdecoder(self.mode, d, a, self.decoderconfig) File "Image.py", line 328, in _getdecoder raise IOError("decoder %s not available" % decoder_name) IOError: decoder group4 not available -- http://mail.python.org/mailman/listinfo/python-list
Re: Tiff Image Reader/writer
I get a decoder error when i do a get pixel on the Image >>> im.getpixel((12,34)) Traceback (most recent call last): File "", line 1, in ? File "Image.py", line 858, in getpixel self.load() File "/usr/local/lib/python2.4/site-packages/PIL/ImageFile.py", line 180, in load d = Image._getdecoder(self.mode, d, a, self.decoderconfig) File "Image.py", line 328, in _getdecoder raise IOError("decoder %s not available" % decoder_name) IOError: decoder group4 not available -- http://mail.python.org/mailman/listinfo/python-list
Powerful Command line parser
Is there a Command line parser in python that can: 1. resolve conflicts 2. specify something like requires 3. and be smart for ex: python test.py --a --b --c --d Case 1: If 'a' is an option 'b' or 'c' cannot be specified. Case 2: atleast one option should be specified Case 3: IF 'a' and 'c' are given then 'd' has to be given or many such cases. I was wondering as this is a very common problem there if there is a module that could do these things . 'optparse' is not this smart I guess. -- http://mail.python.org/mailman/listinfo/python-list
Powerful Command line parsers
Is there a Command line parser in python that can: 1. resolve conflicts 2. specify something like requires 3. and smart for ex: python test.py --a --b --c --d Case 1: If 'a' is an option 'b' or 'c' cannot be specified. Case 2: atleast one option should be specified Case 3: IF 'a' and 'c' are given then 'd' has to be given or many such cases. I was wondering as this is a very common problem there if there is a module that could do these things . 'optparse' is not this smart I guess. -- http://mail.python.org/mailman/listinfo/python-list
member variables in python
hi how do I write this better with member variables rather than global as you see below. eg: test-flag = 0 class AA: def __init__(...): def methos(self,...): global test-flag test-flag = xx instead of something like above ..how do i put it i terms of member variables? -- http://mail.python.org/mailman/listinfo/python-list
Re: member variables in python
ok I reason I was going with globals is that i use this variable in another class something like this along with above testflag = 0 class AA: def __init__(...): def methos(self,...): global testflag testflag = xx class BB: def __init__(...): def method2(..): if testflag: print "do this" is there a better way to access this if we go with what you mentioned in another class .. I wanted to avoid globals thats the reason i am looking for better solution .. -- http://mail.python.org/mailman/listinfo/python-list
Re: member variables in python
I see that.But here in my case the testflags is computed inside the member function something like class AA: def __init__(self): self.test_flag = 0 # initialize def methods(self, value): save_value = _munge(value) self.test_flag = save_value Now basically I want use this self.test_flag in another class .. Basically I wanted to know if there is a better way than what i did before..not necessarly a member variable way ..just looking for a more eligant way if there is any.. -- http://mail.python.org/mailman/listinfo/python-list