Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Multimedia (https://www.delphipraxis.net/16-multimedia/)
-   -   Delphi Noise (grains in graphics) other than random (https://www.delphipraxis.net/153274-noise-grains-graphics-other-than-random.html)

WojTec 27. Jul 2010 16:10

Noise (grains in graphics) other than random
 
This is standard random mono noise generator for images:
Delphi-Quellcode:
for J := 0 to ASource.Height - 1 do
begin
  for I := 0 to ASource.Width - 1 do
  begin
    Amount := Random(AFactor) - (AFactor shr 1);

    Bits.R := IntToByte(Bits.R + Amount);
    Bits.G := IntToByte(Bits.G + Amount);
    Bits.B := IntToByte(Bits.B + Amount);
  end;
end;
In PSP I see 2 other methods called uniform and gaussian. Do you know how it working? And maybe do you know another color/mono noise?

blackfin 27. Jul 2010 16:23

AW: Noise other than random
 
A common form of noise is "perlin noise". It is often used for generating cloud textures or to create a detail map for graphics / textures.

Here is a website where you can download a project that generates perlin noise with Delphi:

http://www.efg2.com/Lab/Library/Delp...phics/Math.htm

just scroll down the site or text-search for "perlin noise" when the website has opened.
Maybe this helps a little bit?

WojTec 27. Jul 2010 17:50

Re: Noise other than random
 
I saw this app, it's quite nice. But I'm not sure how to use Perlin Noise to generate grains on photo?

blackfin 27. Jul 2010 18:05

AW: Noise other than random
 
First, you generate the noise map with the perlin noise function shown in the project.
The noise map has to be the same size as your original photo, so make a noise map with the same size.
If you want extreme graininess, just use Layer 1 or 2.
When you have the noise map, that's half the battle.
All what's left to do is to mix the original photo and the noise map together, using color multiplication, blending, color addition or some other color mixing algorithm, depending on the effect you want to achieve:)

WojTec 27. Jul 2010 19:11

Re: Noise other than random
 
But grain parameter do not generate less or more grains (as sample from 1st post) :(
However PN is good function for my app, I'll add it.

Medium 28. Jul 2010 05:50

AW: Noise other than random
 
The two methods you named only differ in their probability distribution function. Since the Delphi RNG should yield uniformly distributed results, your code sample already implements uniform noise. For gaussian noise, you'd need normal distributed numbers, which can for example be achieved by scaling the results of the uniform RNG by the normal distribution function. Another approach would be an RNG that naturally yields normal distributed values, for which I don't have a working example at hand right now.

The aforementioned Perlin noise is quite different from those, since it is a fractal (once more than the first octave is used), which is not any less good, but an entirely different class of noise.

All types of noises can be applied in 4 ways:
1) Binary monochromatic, meaning the RNG value is thresholded at some point to black and white, and mixed into the image in some manner (usually scaled to 0..2 and multiplied, or scaled to -1..1 and added (and clamped of course))
2) Binary colored, which is the same, but with new values for each color channel (further dividable into applications to various color models)
3) Continuous monochromatic, where the value of the RNG is taken as is, and interpreted as brightness, mixed with the image
4) Continuous colored, well, should be obvious ;)

A fifth method may be called "ternary", since two thresholds are applied. Values smaller than the low threshold are black, those between low and high are nothing, and those above the high threshold are white (or "color" if a colored noise is wanted). By choosing these thresholds close to the interval borders, you get the so called "salt and pepper"-noise, which is few, but strongly miscolored pixels. That can also be done using a distribution function of ones choice, of course, as with any other means of number generation (also Perlin noise may be used for that), though uniform seems to be commonly used.

As for the application of noise to an image, there seems to be no "right" way, when not talking about a specific type or effect to simulate. Those mentioned under 1) are common, but by no means all there is. Pretty much any mixing may be used, and is well up to your likings.

WojTec 28. Jul 2010 09:59

Re: Noise other than random
 
Thanks for intoduction to noise theory :) Could I ask for some examples?


Alle Zeitangaben in WEZ +1. Es ist jetzt 21:34 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz