How to generate multiple images/save to files .. with random noise ? lazarus / 39-Graphics ---------------------------------------------------------------------- yahoo000 · 2021-03-05 00:00 How to generate multiple images/save to files .. with random noise ? Is there any free component with some examples how to do it ? so I got one original image "image1.jpg" and I would like to generate 300 images with random noise "image1_random1.jpg" "image1_random2.jpg" thanks for help. ---------------------------------------------------------------------- lainz · 2021-03-05 01:04 Yes, using BGRABitmap is easy Color noise: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure Noise(Bitmap: TBGRABitmap);var  i: integer;  p: PBGRAPixel;begin  p := Bitmap.Data;   for i := Bitmap.NBPixels - 1 downto 0 do  begin    p^.red := Random(256);    p^.green := Random(256);    p^.blue := Random(256);    //p^.alpha := Random(256);    Inc(p);  end;end; Black and white noise: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure NoiseBW(Bitmap: TBGRABitmap);var  i: integer;  p: PBGRAPixel;  c: byte;begin  p := Bitmap.Data;   for i := Bitmap.NBPixels - 1 downto 0 do  begin    c := Random(2);    p^.red := c + 255;    p^.green := c + 255;    p^.blue := c + 255;    //p^.alpha := Random(256);    Inc(p);  end;end; Just do something like this: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i var  i: integer;  bmp: TBGRABitmap;begin  bmp := TBGRABitmap.Create(640,480);  for i:=1 to 300 do  begin    NoiseBW(bmp);    bmp.SaveToFile('image1_random' + i.ToString() + '.jpg');  end;  bmp.Free;end; Edit: add to uses clause BGRABitmap, BGRABitmapTypes. ---------------------------------------------------------------------- lainz · 2021-03-05 01:08 But I don't get if you want to generate random noise over the image with alpha perhaps? - If this is the case, you can use alpha channel, load the image, and put noise over it. Or generate noise with the pixels of the bitmap itelf? - Maybe you can shuffle the array pixels somehow? ---------------------------------------------------------------------- yahoo000 · 2021-03-05 01:31 Quote from: lainz on March 05, 2021, 02:08:19 amBut I don't get if you want to generate random noise over the image with alpha perhaps? - If this is the case, you can use alpha channel, load the image, and put noise over it. Or generate noise with the pixels of the bitmap itelf? - Maybe you can shuffle the array pixels somehow? But I don't get if you want to generate random noise over the image with alpha perhaps? - If this is the case, you can use alpha channel, load the image, and put noise over it. "yes exactly , over  the image" like in the below example https://i.imgur.com/qgkUHtl.png on the right you got noised original image but noised "strength=95" I would like to generate let's say 300 images ... but with random noise strength "0.1 - 100" .. ---------------------------------------------------------------------- lainz · 2021-03-05 01:45 That's easy too. With the same noise function just provide the alpha channel in a parameter. Then blend your image with the noise and save it. I'm not at the pc right now to write it. But you can do looking at the wiki examples maybe? ---------------------------------------------------------------------- yahoo000 · 2021-03-05 02:01 Quote from: lainz on March 05, 2021, 02:45:08 amThat's easy too. With the same noise function just provide the alpha channel in a parameter. Then blend your image with the noise and save it. I'm not at the pc right now to write it. But you can do looking at the wiki examples maybe? I cannot find it in wiki can you show some example ? thank you ---------------------------------------------------------------------- lainz · 2021-03-06 16:08 Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure NoiseBW(Bitmap: TBGRABitmap; Alpha: byte);var  i: integer;  p: PBGRAPixel;  c: byte;begin  p := Bitmap.Data;   for i := Bitmap.NBPixels - 1 downto 0 do  begin    c := Random(2);    p^.red := c + 255;    p^.green := c + 255;    p^.blue := c + 255;    p^.alpha := Alpha;    Inc(p);  end;end; {$R *.lfm} { TForm1 } procedure TForm1.Button1Click(Sender: TObject);var  i: integer;  bmp, bmpNoise, bmpComposite: TBGRABitmap;begin  bmp := TBGRABitmap.Create('image1.jpg');  bmpNoise := TBGRABitmap.Create(bmp.Width, bmp.Height);  bmpComposite := TBGRABitmap.Create(bmp.Width, bmp.Height);  for i:=1 to 10 do  begin  bmpNoise.FillTransparent();    NoiseBW(bmpNoise, Random(256));    bmpComposite.PutImage(0, 0, bmp, dmSet);    bmpComposite.PutImage(0, 0, bmpNoise, dmDrawWithTransparency);    bmpComposite.SaveToFile('image1_random' + i.ToString() + '.jpg');  end;  bmpComposite.Free;  bmpNoise.Free;  bmp.Free;end; ---------------------------------------------------------------------- yahoo000 · 2021-03-06 16:28 works great !!! thanks