Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.013 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'else:': 0.03; '"__main__":': 0.07; 'pixel': 0.07; 'blue': 0.09; 'dict': 0.09; 'advance': 0.10; 'def': 0.10; '0.0,': 0.16; '65536': 0.16; 'thanx': 0.16; 'to:name:python-list@python.org': 0.20; 'trying': 0.21; 'import': 0.21; 'skip:c 70': 0.22; 'values': 0.26; 'set.': 0.27; 'message-id:@mail.gmail.com': 0.27; 'dictionary': 0.29; 'falls': 0.29; 'subject: : ': 0.30; 'code': 0.31; 'print': 0.32; 'to:addr:python-list': 0.33; 'skip:& 20': 0.33; 'received:google.com': 0.34; 'identified': 0.35; 'continue': 0.35; 'something': 0.35; 'created': 0.36; 'but': 0.36; 'subject:with': 0.36; 'data': 0.37; 'green': 0.38; 'to:addr:python.org': 0.39; 'red': 0.60; 'first': 0.61; 'here': 0.65; 'color': 0.69; '8bit%:100': 0.70; '3000': 0.71; 'increase': 0.72; '\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:date:message-id:subject:from:to :content-type; bh=M5TAW/FBBRF1mRwQaqOqBe/IhRCvsiG9jc0B7wz1N5Y=; b=mVqpR92JTw9rrhEJ//KfFUlH8mDrt3wFebUTXpWeHUAXuqTbgH4gU+PhoP1+0mwOJd DIIU3VoPk7Dg4eSRRP4GddLrDkK+9L8KkVAJ56eEUX7tjbZNquJ0uoc0KfNVagWkr2Us cNxO3Thw2OG6cdxqo2mMYet/z14QZWHHU0NGuc8IA/ZbY+fmabvo55hVkJqIQkkiai6E UbqunY10R0XwG55YHcTiHEwUnn0kYByicwVDdzOQEGyQUAuFRV6/1PqbJymSbFmfoM3H JRcOZeiGaBeCb80lVeRg8TRYc359rORO88aztxwgGYO425bBSN3cJPKAgCxayY3c2jdX g1YA== MIME-Version: 1.0 X-Received: by 10.50.212.38 with SMTP id nh6mr7494116igc.72.1363015385762; Mon, 11 Mar 2013 08:23:05 -0700 (PDT) Date: Mon, 11 Mar 2013 16:23:05 +0100 Subject: working with dict : incrementing dict dynamically From: inshu chauhan To: "python-list@python.org" Content-Type: multipart/alternative; boundary=14dae93408ffe4594104d7a7bf0c X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 81 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1363015388 news.xs4all.nl 6966 [2001:888:2000:d::a6]:48475 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:41070 --14dae93408ffe4594104d7a7bf0c Content-Type: text/plain; charset=ISO-8859-1 I am trying to create a dictionary with a key and its values seraching from a data set. But something is going wrong. This is the first time I am working with dicts. My code is : import cv def Computesegclass(segimage): num_pixel = 0 for y in xrange(0, segimage.height): for x in xrange(0, segimage.width): if segimage[y,x] == (0.0, 0.0, 0.0): continue else: color = segimage[y,x] blue = color[0] green = color[1] red = color[2] region_num = blue + 256 * green + 65536 * red print region_num segments = dict({region_num : num_pixel}) if region_num == region_num: num_pixel = +1 print segments if __name__== "__main__": segimage = cv.LoadImageM("Z:/Segmentation/segmentation_numbers_00000.tif", cv.CV_LOAD_IMAGE_UNCHANGED) print segimage Computesegclass(segimage) here I am traversing through an image which is 3000 x 3000. for each pixel I calculate a region number. What I am trying to do is increase the num_pixel by 1 if that pixel falls in the same region which is identified by region_num. How can I do it in dict created ? Thanx in Advance --14dae93408ffe4594104d7a7bf0c Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
I am trying to create a dictionary with a k= ey and its values seraching from a data set. But something is going wrong. = This is the first time I am working with dicts.

My code is :
import cv
def Computesegclass(segimage):
=A0=A0=A0 num_pixel =3D= 0
=A0=A0=A0=A0=A0=A0=A0 for y in xrange(0, segimage.height):
=A0=A0= =A0=A0=A0=A0=A0 for x in xrange(0, segimage.width):
=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 if segimage[y,x] =3D= =3D (0.0, 0.0, 0.0):
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 continue
=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0 else:
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 c= olor =3D segimage[y,x]
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 blu= e =3D color[0]
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 green =3D c= olor[1]
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 red =3D color[2]=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 region_num =3D blue + 256 *= green + 65536 * red
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 print region_num
=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 segments =3D dict({region_num : num_pi= xel})
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 if region_num =3D=3D= region_num:
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 n= um_pixel =3D +1
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 print seg= ments

if __name__=3D=3D "__main__":
=A0=A0=A0 segimage =3D cv.LoadIm= ageM("Z:/Segmentation/segmentation_numbers_00000.tif", cv.CV_LOAD= _IMAGE_UNCHANGED)
=A0=A0=A0 print segimage
=A0=A0=A0 Computesegclass(= segimage)


here I am traversing through an image which is 3000 x 3000. for each = pixel I calculate a region number. What I am trying to do is increase the n= um_pixel by 1 if that pixel falls in the same region which is identified by= region_num. How can I do it in dict created ?

Thanx in Advance


--14dae93408ffe4594104d7a7bf0c--