hughesadam87 / pyparty

Drawing and analyzing particles on images
Other
35 stars 17 forks source link

More generalized noise #35

Open hughesadam87 opened 10 years ago

hughesadam87 commented 10 years ago

There are several generalizations to improve noise.

First, the "multicolor" and the "color" are just numpy.random distributions applied to gray and rgb images. They could be consolidated into a single call if you build a general function for mapping a numpy distribution to a rgb and gray image. This is partially done in "normal".

In this new framework, normal and "color (maybe rename random)" would just be promotions of 2 most common noises. Normal has some keywords that make calling the numpy API more intuitive, but in general, any distribution should be accessible with "size" being the only keyword auto-set. Just need a general parser for 1-channel and 3-channel. The _parse_intensity is ok for single intensities, but it would be better if the distribution returned the desired array, then we just masked based on xmin, xmax (see the normal() function for this step) so that nosie doesn't exceed the datatypes allowed.

hughesadam87 commented 10 years ago

Thinking about this a big more, should also optionally be able to return just noise. Maybe I scrap passing the image directly and just return noise based on dimensions of an image.

noise = normal_noisy(img.shape, blah) noisyimg = img + noise

How bout this, if I pass in img, noise added to img. If I pass in shape, noise returned.

Maybe noise should always be rgb, but I can specify type conversion

normal_noisy(img.shape, 'gray')

I dunno...

Then maybe a nice interface would be for canvas to have an add_noise() feature that wraps function calls and stores noise separatly.

canvas.add_noise('gaussian', **kwargs)

Ya, probably this is the best way, then just refactor notebooks. In the notebooks that use noise, I need to extract the noise anyway, and that just turns out to be a pain in the ass.