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
 TImageEnMView alpha channel
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

spetric

Croatia
308 Posts

Posted - Jan 25 2019 :  09:34:12  Show Profile  Reply
Hi,

I'm trying to set and fill alpha channel for TIEBitmap in TImageEnMView, but it does not work (it worked only on some specific png image - without alpha channel) :


  mView->SetImage(0, ienIO->IEBitmap);
  TIEBitmap *map = mView->GetTIEBitmap(0, true);
  if (!map->HasAlphaChannel)
     map->AlphaChannel->Fill(255);
  mView->ReleaseBitmap(0, true);


When such map is recalled:


TIEBitmap *map0 = mView->GetTIEBitmap(0, true);


alpha channel of map0 is NULL.
So, the question is how to add alpha channel to TIEBitmap contained in
TImageEnMView?


xequte

38180 Posts

Posted - Jan 25 2019 :  19:59:42  Show Profile  Reply
Hi Sinisa

Do you mean map0->AlphaChannel is NULL? ImageEn should create the AlphaChannel if it does not exist in this case.


Nigel
Xequte Software
www.imageen.com
Go to Top of Page

spetric

Croatia
308 Posts

Posted - Jan 26 2019 :  14:36:21  Show Profile  Reply
Hi Nigel,

Exactly. I don't know what I'm doing wrong.
Here is how I set alpha chanel in ImageEnMView:


//---------------------------------------------------------------------------
void __fastcall TForm1::btnLoadMasterClick(TObject *Sender)
{
if (openDialog->Execute())
   {
   ienIO->LoadFromFile(openDialog->FileName);
   // delete additinal images
   while (mView->ImageCount > 2)
	  mView->DeleteImage(mView->ImageCount - 1);
   // append or insert image
   if (mView->ImageCount == 0)
	  {
	  // test
	  //if (!ienIO->IEBitmap->HasAlphaChannel)
	  //	 ienIO->IEBitmap->AlphaChannel->Fill(255);
	  mView->InsertImage(0);
	  mView->SetImage(0, ienIO->IEBitmap);
	  mView->ImageTopText[0] =  "master";
	  }
   else
	  mView->SetImage(0, ienIO->IEBitmap);
   TIEBitmap *map = mView->GetTIEBitmap(0, true);
   if (!map->HasAlphaChannel)
	  map->AlphaChannel->Fill(255);
   mView->ReleaseBitmap(0, true);
   ieView->SetExternalBitmap(mView->IEBitmap);
   }
}


When I recall the image again, here is what I get:



As you can see map0->AlphaChannel is NULL (line 106).
Of course, when code at line 107 is executed it will create new alpha channel.
Actually, every time I execute this piece of code, alpha channel is recreated...at least I think so.

Update: This problem with alpha channel never occurs with ImageEnView or ImageEnVect IEBitmap. But, at least I discovered that I misspelled Hamming and wrote Humming :)
Go to Top of Page

xequte

38180 Posts

Posted - Jan 27 2019 :  17:22:40  Show Profile  Reply
Hi Sinisa

Can you please attach your test image.



Nigel
Xequte Software
www.imageen.com
Go to Top of Page

spetric

Croatia
308 Posts

Posted - Jan 28 2019 :  04:05:10  Show Profile  Reply
Hi Nigel,

Any loaded jpg image will behave the same. If loaded image already has
alpha channel (png) it will work ok.

I've added few test lines when loading image:

if (openDialog->Execute())
   {
   ienIO->LoadFromFile(openDialog->FileName);
   // delete additinal images
   while (mView->ImageCount > 2)
	  mView->DeleteImage(mView->ImageCount - 1);
   // append or insert image
   if (mView->ImageCount == 0)
	  {
	  // test
	  //if (!ienIO->IEBitmap->HasAlphaChannel)
	  //	 ienIO->IEBitmap->AlphaChannel->Fill(255);
	  mView->InsertImage(0);
	  mView->SetImage(0, ienIO->IEBitmap);
	  mView->ImageTopText[0] =  "master";
	  }
   else
	  mView->SetImage(0, ienIO->IEBitmap);
   TIEBitmap *map = mView->GetTIEBitmap(0, true);
   if (!map->HasAlphaChannel)
	  map->AlphaChannel->Fill(255);    // alpha channel created
   mView->ReleaseBitmap(0, true);
   // check image again
   map = mView->GetTIEBitmap(0, true);     // alpha channel is null
   mView->ReleaseBitmap(0, true);
   ieView->SetExternalBitmap(mView->IEBitmap);
   }


Here are two images attached (jpg and png). Jpg does not have alpha channel and
I can not add alpha channel in ImageEnMView.



attach/spetric/2019128452_f2d_test.zip
450.71 KB
Go to Top of Page

xequte

38180 Posts

Posted - Jan 29 2019 :  16:00:42  Show Profile  Reply
Thanks for the detail.

Actually, ImageEn is seeing that the Alpha channel contains no Alpha, so when you retrieve it the second time, it discards the alpha channel.

It works if you either:
- Fill Alpha channel with <255 value
- Set map.AlphaChannel.Full := False;

Sorry for the confusion.



var
  map: TIEBitmap;
begin
   ienIO.LoadFromFile( IEAddBackslash( ExtractFilePath( Application.ExeName )) + 'image.jpg' );

   // delete additinal images
   while (mView.ImageCount > 2) do
	  mView.DeleteImage(mView.ImageCount - 1);

   // append or insert image
   if (mView.ImageCount = 0) then
    begin
      // test
      //if (!ienIO.IEBitmap.HasAlphaChannel)
      //	 ienIO.IEBitmap.AlphaChannel.Fill(255);
      mView.InsertImage(0);
      mView.SetImage(0, ienIO.IEBitmap);
      mView.ImageTopText[0] :=  'master';
    end
    else
      mView.SetImage(0, ienIO.IEBitmap);

   map := mView.GetTIEBitmap(0, true);
   if (not map.HasAlphaChannel) then
	  map.AlphaChannel.Fill(125)
   if (not map.HasAlphaChannel) then
     ShowMessage( 'no alpha channel');
   mView.ReleaseBitmap(0, true);

   // check image again
   map := mView.GetTIEBitmap(0, true);    
   if (not map.HasAlphaChannel) then
     ShowMessage( 'no alpha channel');
   mView.ReleaseBitmap(0, true);
end;


Nigel
Xequte Software
www.imageen.com
Go to Top of Page

spetric

Croatia
308 Posts

Posted - Jan 31 2019 :  02:42:01  Show Profile  Reply
Hi Nigel,

Thanks for info.
So, when using ImageEnMView, I can not set all alpha channel pixels to max value (255)?

This is very strange.

I need all alpha pixels to max value (for images without alpha channel), because in the next step image is transformed (perspective warping and resizing - new image) together with alpha channel (I'm using OpenCV 4.0 for that):


if (outImage)
   {
   Size size = imgSample.size();
   // warp and align to sample using homography matrix
   warpPerspective(imgMaster, imgReg, homography, size);
   if (alphaMaster.empty())
      alphaReg = Mat();
   else    // warp alpha channel and align to sample
      warpPerspective(alphaMaster, alphaReg, homography, size);
   }
else
   imgReg = Mat();



Of course, prior to transformation function, I can create alpha channel (if it does not exists) and fill it with 255 (it works), or I can set one pixel to 244 when image is loaded. I prefer setting alpha channel once the image is loaded...but setting one pixel value to 244 looks like a brute hack.
Go to Top of Page

xequte

38180 Posts

Posted - Jan 31 2019 :  15:23:14  Show Profile  Reply
Hi Sinisa

Hmmm, let me discuss this with my partner.

In the meantime, you should just be able to use:

   if (!map->HasAlphaChannel)
   {
	  map->AlphaChannel->Fill(255);    // alpha channel created
	  map->AlphaChannel->Full = FALSE; // Force ImageEn to keep alpha channel
   }

Nigel
Xequte Software
www.imageen.com
Go to Top of Page

spetric

Croatia
308 Posts

Posted - Jan 31 2019 :  16:41:00  Show Profile  Reply
Hi Nigel,

Setting Full to false did the job.
I've put this line when loading the image:


if (openDialog->Execute())
   {
   ienIO->LoadFromFile(openDialog->FileName);
   while (mView->ImageCount > 2)
	  mView->DeleteImage(mView->ImageCount - 1);
   if (mView->ImageCount == 0)
      {
      if (!ienIO->IEBitmap->HasAlphaChannel)
	 {
	 ienIO->IEBitmap->AlphaChannel->Fill(255);
         ienIO->IEBitmap->AlphaChannel->Full = false;
	 }
       mView->InsertImage(0);
       mView->SetImage(0, ienIO->IEBitmap);
       mView->ImageTopText[0] =  "master";
       }
   else
      mView->SetImage(0, ienIO->IEBitmap);
   ieView->SetExternalBitmap(mView->IEBitmap);
   }


Thanks a lot,
Siniša
Go to Top of Page

xequte

38180 Posts

Posted - Feb 01 2019 :  04:18:28  Show Profile  Reply
Hi Sinisa

For the next release, we've decided it should return the alpha channel even when it is full.



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