ImageEn for Delphi and C++ Builder ImageEn for Delphi and C++ Builder

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
Forum membership is Free!  Click Join to sign-up
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 RGB value scan for each pixel over a selection
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

Dudskoni

4 Posts

Posted - Oct 13 2012 :  07:58:16  Show Profile  Reply
Folks

Considering that I’ve made a rectangle selection in a image I need to scan each line a put the RGB value in a matrix like this:

[ RGBpixel 1 …. RGBpixeln
….
….
….
…. ]

My intention is to count how many pixel of each color the selection has, e.g. yellow pixels. I suppose I would need to implement a algorithm to make an approximation since I would like to count the yellow pixel (for example) no matter the tone.

Thanks in advance for your help.

Duds

fab

1310 Posts

Posted - Oct 16 2012 :  01:58:44  Show Profile  Reply
Hello,
this code loads a jpeg, select a region (50, 90, 300, 400) and count (and mark) all pixels in the Hue range 22:33, that should be orange-like.
You can remove Selection part to allow user to select using the mouse and the LoadFromFile to process a previously loaded image.
Yellow could be a combination of Hue, Saturation and Luminosity (Val).
Hope this helps.

var
  i, j: integer;
  Hue, Sat, Val: integer;
  orangePixels: integer;
begin
  ImageEnView1.IO.LoadFromFile('input.jpg');
  ImageEnView1.Select(50, 90, 300, 400);  // user can also select using mouse instead of this

  orangePixels := 0;
  ImageEnView1.SelectionBase := iesbBitmap;
  for i:=ImageEnView1.SelY1 to ImageEnView1.SelY2 do
    for j:=ImageEnView1.SelX1 to ImageEnView1.SelX2 do
      if ImageEnView1.IsPointInsideSelection(j, i) then
      begin
        RGB2HSV(ImageEnView1.IEBitmap.Pixels_ie24RGB[j, i], Hue, Sat, Val);
        if (Hue >= 22) and (Hue <= 33) then
        begin
          inc(orangePixels);
          ImageEnView1.IEBitmap.Pixels_ie24RGB[j, i] := CreateRGB(255, 0, 0); // optional: just to mark orange pixels
        end;
      end;

  ShowMessage(Format('Counted %d orange pixels', [orangePixels]));
  ImageEnView1.Update();
end;
Go to Top of Page

Dudskoni

4 Posts

Posted - Oct 18 2012 :  16:33:56  Show Profile  Reply
I didn't have the opportunity to try but it seems a very good idea work with hue. Many thanks.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: