Recent

Author Topic: How to gain Monochromatic Noise from BGRABitmap Grayscale Noise?  (Read 3159 times)

Sanem

  • Full Member
  • ***
  • Posts: 173
HI
I wanted to have a Monochromatic Noise just like my sample pic in Photoshop (amount 120%) as you you can see in screenshots attached below, i tried this code to make what i want with BGRABitmap, but it seems that BGRA makes the noise like Grayscale of the colorful pixels, as you can see in my samples from BGRA the number of colors are more than in Photoshop, (you can zoom in pictures and compare them) so i wanted to know if there is a way to have Monochromatic noise using BGRA??

first Screenshot is my sample noise in photoshop with amount 120%, the next one is result from BGRA noise with opacity 255.
and my project is uploaded here: https://www.dropbox.com/s/eo1pgze6ysxxkoc/TestAddNoise.zip?dl=0

any help appreciated prior
regards

here is my code:

Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ComCtrls, ExtCtrls,
  9.   BGRABitmap, BGRABitmapTypes, BGRAGradients, BGRAGradientScanner;
  10.  
  11. type
  12.  
  13.   { TForm1 }
  14.  
  15.   TForm1 = class(TForm)
  16.     Panel1: TPanel;
  17.     TrackBar1: TTrackBar;
  18.     procedure Panel1Paint(Sender: TObject);
  19.     procedure TrackBar1Change(Sender: TObject);
  20.   private
  21.     { private declarations }
  22.   public
  23.     { public declarations }
  24.   end;
  25.  
  26. var
  27.   Form1: TForm1;
  28.  
  29. implementation
  30.  
  31. {$R *.lfm}
  32.  
  33. { TForm1 }
  34.  
  35. procedure TForm1.Panel1Paint(Sender: TObject);
  36. var
  37.   image1, image2: TBGRABitmap;
  38.   noisescan: TBGRARandomScanner;
  39. begin
  40.   image1 := TBGRABitmap.Create(ClientWidth, ClientHeight);
  41.   image2 := TBGRABitmap.Create(ClientWidth, ClientHeight, clBlack);
  42.   noisescan := TBGRARandomScanner.Create(True, TrackBar1.Position);
  43.   image1.Fill(noisescan);
  44.   image2.PutImage(0, 0, image1, dmDrawWithTransparency);
  45.   image2.Draw(Panel1.Canvas, 0, 0, False);
  46.   image2.SaveToFile('Pics\' + IntToStr(TrackBar1.Position) + '.png');
  47.   image1.Free;
  48.   image2.Free;
  49. end;
  50.  
  51. procedure TForm1.TrackBar1Change(Sender: TObject);
  52. begin
  53.   Panel1.Refresh;
  54.   Form1.Caption := 'Opcaity: ' + IntToStr(TrackBar1.Position);
  55. end;
  56.  
  57. end.
  58.  
« Last Edit: July 26, 2016, 09:59:24 am by simin_sh »

circular

  • Hero Member
  • *****
  • Posts: 4220
    • Personal webpage
Re: How to gain Monochromatic Noise from BGRABitmap Grayscale Noise?
« Reply #1 on: July 26, 2016, 10:32:28 am »
As far as I can see, 255.png is grayscale and hasn't more than 256 different colors.

Note that you can simplify the code like this:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Panel1Paint(Sender: TObject);
  2. var
  3.   image1: TBGRABitmap;
  4.   noisescan: TBGRARandomScanner;
  5. begin
  6.   image1 := TBGRABitmap.Create(ClientWidth, ClientHeight, clBlack);
  7.   noisescan := TBGRARandomScanner.Create(True, TrackBar1.Position);
  8.   image1.Fill(noisescan, dmDrawWithTransparency);
  9.   image1.Draw(Panel1.Canvas, 0, 0, False);
  10.   image1.SaveToFile('Pics\' + IntToStr(TrackBar1.Position) + '.png');
  11.   image1.Free;
  12. end;
« Last Edit: July 26, 2016, 10:35:30 am by circular »
Conscience is the debugger of the mind

Sanem

  • Full Member
  • ***
  • Posts: 173
Re: How to gain Monochromatic Noise from BGRABitmap Grayscale Noise?
« Reply #2 on: July 26, 2016, 10:49:25 am »
thank you so much for your replay
yep it was a test for having a background with different colors if i wanted to.
but about the noise, i wanna gain something like Monochromatic noise in Photoshop, as you can see in first screenshot, i meant that when you zoom in you see less number of colors, it seems more Black and white, but in BGRA noise it seems that the number of colors that we can see are more, i mean it seems like using more grayscale colors, i want something monochromatic, i thought maybe i can play with colors of pixels and manage them by decreasing and increasing the amount of them to gain that monochromatic Noise that seems more Black and white.
i was thinking if there is similar concept for noise in BGRA??

circular

  • Hero Member
  • *****
  • Posts: 4220
    • Personal webpage
Re: How to gain Monochromatic Noise from BGRABitmap Grayscale Noise?
« Reply #3 on: July 26, 2016, 01:42:47 pm »
Oh I think I understand. You would like to have more values near black and white and less middle values?

I would suggest to make a copy of the class TBGRARandomScanner and make your own. Then in the ScanNextPixel function, you could replace random(256) by something else that would be more like what you want.

For example:
random(2)*255   -->   would give black'n'white only.
Sin65536[random(65536)] div 256   -->   would give more black'n'white but still some gray

Conscience is the debugger of the mind

Sanem

  • Full Member
  • ***
  • Posts: 173
Re: How to gain Monochromatic Noise from BGRABitmap Grayscale Noise?
« Reply #4 on: July 26, 2016, 02:04:54 pm »
Thank you so much again, i will give it a try, i have already made a formula for what i want, but in my test i replace the pixels directly by the custom calculated(from formula) value that i want.

circular

  • Hero Member
  • *****
  • Posts: 4220
    • Personal webpage
Re: How to gain Monochromatic Noise from BGRABitmap Grayscale Noise?
« Reply #5 on: July 26, 2016, 03:04:19 pm »
Indeed, you can simply access the data directly  :)
Conscience is the debugger of the mind

 

TinyPortal © 2005-2018