<div dir="ltr"><div><div><div>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.<br><br></div>My code is :<br>
<br>import cv <br>def Computesegclass(segimage):<br> num_pixel = 0<br> for y in xrange(0, segimage.height):<br> for x in xrange(0, segimage.width):<br> <br> if segimage[y,x] == (0.0, 0.0, 0.0):<br>
continue<br> else:<br> color = segimage[y,x]<br> blue = color[0]<br> green = color[1]<br> red = color[2]<br> region_num = blue + 256 * green + 65536 * red<br>
print region_num<br> segments = dict({region_num : num_pixel})<br> if region_num == region_num:<br> num_pixel = +1 <br> print segments<br><br>
if __name__== "__main__":<br> segimage = cv.LoadImageM("Z:/Segmentation/segmentation_numbers_00000.tif", cv.CV_LOAD_IMAGE_UNCHANGED)<br> print segimage<br> Computesegclass(segimage)<br><br><br>
</div>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 ?<br>
<br></div>Thanx in Advance<br><div><br><br></div></div>