Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #41072
| Path | csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder3.xlned.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <svenito@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.002 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; 'true,': 0.04; 'case.': 0.05; '"__main__":': 0.07; 'mentioned,': 0.07; 'pixel': 0.07; 'blue': 0.09; 'collections': 0.09; 'dict': 0.09; 'cc:addr:python-list': 0.10; 'advance': 0.10; 'def': 0.10; 'suggest': 0.11; '0.0,': 0.16; '65536': 0.16; 'defaultdict': 0.16; 'thanx': 0.16; 'wrote:': 0.17; 'fix': 0.17; 'email addr:gmail.com>': 0.20; 'trying': 0.21; 'import': 0.21; 'skip:c 70': 0.22; 'cc:2**0': 0.23; 'cc:addr:python.org': 0.25; 'header :In-Reply-To:1': 0.25; 'values': 0.26; 'set.': 0.27; 'message- id:@mail.gmail.com': 0.27; 'comparison': 0.29; 'dictionary': 0.29; 'falls': 0.29; 'skip:& 10': 0.29; 'subject: : ': 0.30; 'code': 0.31; 'print': 0.32; '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; 'test': 0.36; 'correctly': 0.37; 'data': 0.37; 'subject:: ': 0.38; 'green': 0.38; 'your': 0.60; 'red': 0.60; 'john': 0.60; 'skip:u 10': 0.60; 'first': 0.61; 'here': 0.65; 'region.': 0.65; 'color': 0.69; '8bit%:100': 0.70; '3000': 0.71; 'increase': 0.72; '2013': 0.84; 'dict,': 0.84; '\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:in-reply-to:references:date:message-id :subject:from:to:cc:content-type; bh=8K+t8gIjHNgMATTCoQXVCN22Ya59GdIUc1cwkI3Wbvc=; b=tE2OUKiq/a/3e9P70DHqUBgojDB/m/vwZvcMYb+ej3ysYwazVsDh33MQybc98SdYZI VrO2s5a9esXWaI/2XdhBBUb9d7Ze7DNCab2vKpkh9MvAtU/ECTCNCrvZUA65/EpZ8l2W AOLWjq1w9071XV0owp8+w2tblDWXWgHp1qIoNbNIILAp6BDLiYLAAbjVswCQ+FvS41HL mIQ7UEwpPBYRvY8PPD9PIUVzegLrc1VZeWmfivOoFQ0j+5QLlwc7ITEcI4JkPqXFtP0h ahI2UB/Pc/FgZjr+5TWeGbn5ijGk3LocmVTTML7yrYMt7/byOxPzCKb3wJ+bpMDJW5Cq Whlw== |
| MIME-Version | 1.0 |
| X-Received | by 10.180.87.129 with SMTP id ay1mr13551664wib.1.1363017220097; Mon, 11 Mar 2013 08:53:40 -0700 (PDT) |
| In-Reply-To | <CAFqGZRF8yz_+5V1JY-TV6ZH2LwzDh17AfqikPw_ALgM3qwN_Vw@mail.gmail.com> |
| References | <CAFqGZRF8yz_+5V1JY-TV6ZH2LwzDh17AfqikPw_ALgM3qwN_Vw@mail.gmail.com> |
| Date | Mon, 11 Mar 2013 15:53:39 +0000 |
| Subject | Re: working with dict : incrementing dict dynamically |
| From | Sven <svenito@gmail.com> |
| To | inshu chauhan <insideshoes@gmail.com> |
| Content-Type | multipart/alternative; boundary=f46d0444e8893a2d2304d7a82d07 |
| Cc | "python-list@python.org" <python-list@python.org> |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.3192.1363017229.2939.python-list@python.org> (permalink) |
| Lines | 126 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1363017229 news.xs4all.nl 6980 [2001:888:2000:d::a6]:58982 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:41072 |
Show key headers only | View raw
[Multipart message — attachments visible in raw view] - view raw
On 11 March 2013 15:23, inshu chauhan <insideshoes@gmail.com> wrote:
> 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
>
>
If I am understanding you correctly you want to accumulate a pixel count
for each region. I would suggest a default dict, and that you do something
like
from collections import defaultdict
def ComputeSegClass(seqimage):
segments = defaultdict(int)
<snip>
if region_num == region_num:
segments[region_num] += 1
But as John mentioned, your comparison here will always be true, so you
will need to fix this to test for your case.
--
./Sven
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: working with dict : incrementing dict dynamically Sven <svenito@gmail.com> - 2013-03-11 15:53 +0000
csiph-web