Recent

Author Topic: the VectorizeMonochrome function cannt get the right path point  (Read 2852 times)

bills

  • New Member
  • *
  • Posts: 44
the VectorizeMonochrome function cannt get the right path point
« on: January 14, 2019, 03:27:36 pm »
Hi, i made a simple bitmap which is black background and there is a white rectangle in it.
the image file: aa.bmp is in the  attachment.

I try to get the  white rectangle border vectorize path by the code:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. var
  3.   i: integer;
  4.   custBmp:TBGRACustomBitmap;
  5.   polyPoiF: ArrayOfTPointF;
  6.   sFn: string;
  7. begin
  8.  
  9.   sFn := ExtractFilePath(ParamStr(0)) + 'aa.bmp';
  10.   if fileExists(sFn) = false then
  11.   begin
  12.    memo1.Append('The file is not exist:' + sFn);
  13.    exit;
  14.   end;
  15.  
  16.   custBmp := TBGRABitmap.Create(300, 300);
  17.   custBmp.LoadFromFile(sFn);
  18.  
  19.   polyPoiF := VectorizeMonochrome(custBmp, 1, false);
  20.  
  21.   for i := 0 to high(polyPoiF) do
  22.     memo1.Append(intToStr(i) + ': [' + floatToStr(polyPoiF[i].x) + ',' + floatToStr(polyPoiF[i].y) + ']');
  23.  
  24. end;    

I get the result:
5: [229,214]
6: [229,249]
7: [72,249]
8: [72,214]

The correct result should be:
5: [295,216]
6: [295,253]
7: [8,253]
8: [8,216]

Wheret's my wrong?
Thanks.

My lazarus version is 1.8.4, FPC 3.0.4, bgrabitmap-9.9.2,windows 8.
All source code is in attachment.





« Last Edit: January 14, 2019, 03:38:11 pm by bills »

circular

  • Hero Member
  • *****
  • Posts: 4195
    • Personal webpage
Re: the VectorizeMonochrome function cannt get the right path point
« Reply #1 on: January 14, 2019, 10:10:33 pm »
Hmmm are you sure about the expected values?

By looking at the picture, it seems to me that those coordinates are kind of what they should be.
Conscience is the debugger of the mind

bills

  • New Member
  • *
  • Posts: 44
Re: the VectorizeMonochrome function cannt get the right path point
« Reply #2 on: January 15, 2019, 01:54:07 am »
Hmmm are you sure about the expected values?

By looking at the picture, it seems to me that those coordinates are kind of what they should be.

thank you circular.

I manual measured the rectangle point's position in photoshop, i found the point' x y produced by this program is have some difference to the actual value.

for example,the right bottom point's xy in photoshop is about: 295,252,but the program result is :229,249

the attachment picture show the photoshop measure result and the program result.

bills

  • New Member
  • *
  • Posts: 44
Re: the VectorizeMonochrome function cannt get the right path point
« Reply #3 on: January 15, 2019, 07:56:59 am »
Hmmm are you sure about the expected values?

By looking at the picture, it seems to me that those coordinates are kind of what they should be.

hello circular, i found a solution that if i save the bmp format file as 16 bit deepth,the program will get the right result,but when save as 32 bit deepth,the result will has error.

If the bmp file is 32 bit,get the wrong result:

0: [0,0]
1: [0,300]
2: [300,300]
3: [300,0]
4: [-3.402823061E38,-3.402823061E38]
5: [229,50]
6: [229,180]
7: [72,180]
8: [72,50]
9: [-3.402823061E38,-3.402823061E38]
10: [229,210]
11: [229,251]
12: [72,251]
13: [72,210]

If the bmp file is 16 bit,get the right result:
0: [30,180]
1: [30,210]
2: [270,210]
3: [270,180]

the first attachment is 16 bit bmp file.
the second attachment is 32 bit bmp file.
the third attachment show the bmp file content, i.e. the black ractangle position.
« Last Edit: January 15, 2019, 08:03:21 am by bills »

circular

  • Hero Member
  • *****
  • Posts: 4195
    • Personal webpage
Re: the VectorizeMonochrome function cannt get the right path point
« Reply #4 on: January 16, 2019, 07:07:41 pm »
Hmm I opened the 32bit image with LazPaint. It seems the alpha values are not set correctly.

Problem is the 32bit BMP format has two meanings : either RGB and no alpha channel (just padded with an extra byte) or RGBA (where alpha channels matters)

It seems that Photoshop considers last channel to be just padding and so the alpha value changes within in the image.

So I would suggest to avoid this format for interchange.
Conscience is the debugger of the mind

bills

  • New Member
  • *
  • Posts: 44
Re: the VectorizeMonochrome function cannt get the right path point
« Reply #5 on: January 17, 2019, 08:25:46 am »
Thank you circular.

i test a png format file,the result is right.

The VectorizeMonochrome is a very good function.

circular

  • Hero Member
  • *****
  • Posts: 4195
    • Personal webpage
Re: the VectorizeMonochrome function cannt get the right path point
« Reply #6 on: January 17, 2019, 09:59:44 pm »
 :)
Conscience is the debugger of the mind

 

TinyPortal © 2005-2018