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
 IEApplyThreshold issue
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

timfa

USA
8 Posts

Posted - Oct 24 2024 :  10:17:52  Show Profile  Reply
I think you have a potential bug in the IEApplyThreshold procedure in the imageenproc.pas unit.

I am simply performing a threshold operation where all pixels below ThresholdValue (e.g., 128) are being set to 0 or 255 in one case or the opposite 255 or 0 in an alternate case. I have a TIEBitmap object named ThresholdImage and makes the following call (the alternate case):

            ThresholdImage.Proc.Threshold(
                        CreateRGB(ThresholdValue,ThresholdValue,ThresholdValue),
                        CreateRGB(ThresholdValue,ThresholdValue,ThresholdValue),
                        CreateRGB(255,255,255), CreateRGB(0,0,0) );

This function in turn calls:
procedure IEApplyThreshold(Bitmap: TIEBitmap; DownLimit, UpLimit, DownVal, UpVal: TRGB; X1, Y1, X2, Y2: Integer; OnProgress: TIEProgressEvent; Sender: TObject);


And in this procedure the following code executes:
for x := X1 to X2 do
    begin
      e := pRGB(ei);
      if (e^.r <= DownLimit.r) then
        e^.r := DownVal.r;
      if (e^.g <= DownLimit.g) then
        e^.g := DownVal.g;
      if (e^.b <= DownLimit.b) then
        e^.b := DownVal.b;
      if (e^.r > UpLimit.r) then
        e^.r := UpVal.r;
      if (e^.g > UpLimit.g) then
        e^.g := UpVal.g;
      if (e^.b > UpLimit.b) then
        e^.b := UpVal.b;
      inc(ei, i);
    end;


What happens in the case I presented is if the first IF for each r, g, b value is true it executes e^.r := DownVal.r which sets the value to 255. Then, further down it executes "if (e^.r > UpLimit.r)" and since we already changed e^.r in the first IF to 255, this second IF is true and sets e^.r := UpVal.r, i.e., it sets it to 0. I think this is wrong.

I think the code should be changed to:

      if (e^.r <= DownLimit.r) then
        e^.r := DownVal.r
      else if (e^.r > UpLimit.r) then
        e^.r := UpVal.r;

      if (e^.g <= DownLimit.g) then
        e^.g := DownVal.g
      else if (e^.g > UpLimit.g) then
        e^.g := UpVal.g;

      if (e^.b <= DownLimit.b) then
        e^.b := DownVal.b
      else if (e^.b > UpLimit.b) then
        e^.b := UpVal.b;

Thank you for considering this issue.


Tim F

xequte

38566 Posts

Posted - Oct 24 2024 :  18:29:59  Show Profile  Reply
Thanks for the report, Tim,

I'll need to investigate this when I am back in the office in early November.

Nigel
Xequte Software
www.imageen.com
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: