Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: Error .. Please Help

Reply
Thread Tools

Re: Error .. Please Help

 
 
Ulrich Eckhardt
Guest
Posts: n/a
 
      12-12-2012
Am 12.12.2012 16:00, schrieb inshu chauhan:
> color = image[y,x]
> if color == (0.0,0.0,0.0):
> continue
> else :
> if color == (0.0,255.0,0.0):
> classification = 1
> elif color == (128.0, 0.0, 255.0):
> classification = 2
> elif color == (255.0,0.0,0.0):
> classification = 3
> elif color == (128.0, 128.0, 128.0):
> classification = 4
> elif color == (128.0, 64.0, 0.0):
> classification = 5
> elif color == (0.0, 0.0, 255.0):
> classification = 6
> elif color == (255.0, 0.0, 255.0):
> classification = 7



Use a dict for this, it probably makes things clearer. Something like:

cclasses = {( 0.0, 0.0, 0.0): None,
( 0.0, 255.0, 0.0): 1,
(128.0, 0.0, 255.0): 2, }

if cclasses[color] is not None:
print >> g, x , y , color, cclasses[color]


Some notes:
* Some people (and I think PEP frown upon the table formatting of
the dict.
* d[color] will raise an exception if there is no mapping, but it's
not clear what you want to do with those inputs anyway.
* Comparing floating-point values for equality is always a bit tricky,
as most operations have some rounding. This could mean that you need to
use ranges instead of fixed values. A good approach is to round the
input to integral values first.
* Are you sure that the input uses floating point values but uses
typical 8-bit ranges 0-255? I would expect floating point values between
0 and 1 or integral values between 0 and 255, but not such a mixture.
* Try g.write('{} {} {} {}\n'.format(x, y, color, classification)) to
get code that you will be able to reuse in Python 3. Also, consider
upgrading anyway.


> I am getting the following error..
>
> Traceback (most recent call last):
> File "Z:\modules\Get_Classification.py", line 27, in <module>
> print >> g, x , y , color, classification
> NameError: name 'classification' is not defined
>
> Its simple error of name but m not getting why it should come as I have
> already defined Classification in between if-else loop ??


One comment here: If you don't define "classification" in this loop
iteration, the one from the previous iteration will be used.
Effectively, this tells me that the first pixel unequal to (0,0,0)
already doesn't fit your expectations. Use "import pdb" and
"pdb.set_trace()" to get into debugging mode, which is a useful skill
anyway.

Good luck!

Uli


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Please please please help this guy with his open source java app casioculture@gmail.com Java 4 05-05-2005 08:24 AM
Console profile for Windows app in VC++ - PLEASE PLEASE PLEASE HELP! MuZZy C++ 7 01-07-2005 08:40 PM
Computer problems please please please help Nick Computer Support 0 06-04-2004 08:49 PM
HELP! HELP! PLEASE, PLEASE, PLEASE tpg comcntr Computer Support 11 02-15-2004 06:22 PM
please help... ...me learn C++ please please please :) KK C++ 2 10-14-2003 02:08 PM



Advertisments