Ask Your Question
0

How to flatten an image with layers into a numpy matrix?

asked 2013-11-26 17:39:17 -0500

dangerboy gravatar image

updated 2013-11-26 18:09:13 -0500

I have an image that is from a video within a while loop.

img = virCam.getImage()

This image has several crop and filter operations... and then I findBlobs()

blobs = img_afterFilters.findBlobs()

From these blobs, I'm only interested in the biggest blob, so I want to fill-color it green:

blobs[-1].draw(width=-1)

I now want to apply this special blob layer onto a empty black image and flatten that image.

blank_img = Image((width, height))  # create the blank image
blank_img.addDrawingLayer(img_afterFilters.dl(-1)) # the last layer has my biggest blob.
blank_img = blank_img.applyLayers() # flatten all the layers onto a single layer?/image?

blank_numpy = blank_img.getNumpy() # get the numpy matrix
# this numpy has all (0,0,0) black tuples in it!... where is my green?

BUT!.. this numpy is filled with black tuples!... somehow I can't figure out a way to copy the green from my filled in blob? Any ideas?

I guess I want to 'flatten' an image without saving it to disk?

edit retag flag offensive close merge delete

Comments

# This line will give me what I want as a black and white image. BUT, it also crops to the size of the blob. I don't want cropping in this case...: blank_img = blobs[-1].blobMask()

dangerboy gravatar imagedangerboy ( 2013-11-26 18:15:49 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2013-12-02 12:13:26 -0500

dangerboy gravatar image

updated 2013-12-02 12:18:04 -0500

Actually the above code in my question works...

My problem was in how I was indexing the numpy array! So... let me say this so others don't make my silly code mistake:

To find the exact size of your numpy matrix

(num_of_columns, num_of_rows, color_rgb_tuple) = black_numpy.shape
# answer is: (360,180,3)

To find the rgb tuple for a specific pixel at row 50 and column 300:

color_tuple = black_numpy[300,50]
# anser is: (0,255,0)

(this is backwards from what I was used to in Matlab... so column number first, row number second!!!)

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2013-11-26 17:39:17 -0500

Seen: 842 times

Last updated: Dec 02 '13