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
 Mapping Pixels
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

pierrotsc

USA
499 Posts

Posted - Jul 31 2013 :  07:44:37  Show Profile  Reply
This is more a coding question I need help with. i am trying an efficient way to map pixels.
I am using a grayscale image with 256 shades of gray.
Let's say that i have Zone 0 that have pixels values from 0 to 12 and zone i with values from 13 to 38.

I use imageenview.SelectColors(CreateRGB(0, 0, 0),
CreateRGB(12, 12, 12), iespAdd); to select 0.

Now if i want to map the zone 0 pixels to zone 1 pixels, how would i do that.
For example, pixels 0 should be now 13 and so on.
The thing is that each zone does not have the same number of pixels. So i guess, it would be mapped as a gradient.

I hope some smart coder as an idea on how to achieve that.
Thanks.
P

fab

1310 Posts

Posted - Aug 15 2013 :  02:43:51  Show Profile  Reply
The fastest way (and where you have more control) is to loop among all pixels and map (with a LUT) each pixel to the right value. For example:
const
  MAP: array [0..255] of byte = (
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,   // zone0: 0..12
    1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // zone1: 13..38
    2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, // zone2?: ...
    ...etc...
  );
var
  i, j: integer;
  pb: pbyte;
begin
  ImageEnView1.LegacyBitmap := false;
  ImageEnView1.IEBitmap.PixelFormat := ie8g;

  for i := 0 to ImageEnView1.IEBitmap.Height - 1 do
  begin
    pb := ImageEnView1.IEBitmap.ScanLine[i];
    for j := 1 to ImageEnView1.IEBitmap.Width do
    begin
      pb^ := MAP[pb^];
      inc(pb);
    end;
  end;

  ImageEnView1.Update();
end;


You have to fill MAP array with the right desired values. Otherwise you could replace...

pb^ := MAP[pb^];


...with a IF:

if pb^ < 12 then
  pb^ := 0
else if pb^ < 38 then
  pb^ := 1
etc...
Go to Top of Page

pierrotsc

USA
499 Posts

Posted - Aug 15 2013 :  11:36:56  Show Profile  Reply
i found another way by selecting colors and use the cast color to replace the selected pixels.
i'll check your code too.
Thanks.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: