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
 greenscreen
 New Topic  Reply to Topic
Next Page
Author Previous Topic Topic Next Topic
Page: of 2

dracola

Argentina
37 Posts

Posted - Apr 08 2014 :  06:47:05  Show Profile  Reply
is imageen have proc like greenscreen?
i have tried imageen.Proc.SetTransparentColors but not working.

w2m

USA
1990 Posts

Posted - Apr 08 2014 :  11:56:57  Show Profile  Reply
What do you mean by green screen and what do you mean it is not working? We need more details in order to help.

William Miller
Adirondack Software & Graphics
Email: w2m@frontiernet.net
EBook: http://www.imageen.com/ebook/
Apprehend: http://www.frontiernet.net/~w2m/index.html
Custom ImageEn Development
Go to Top of Page

spetric

Croatia
308 Posts

Posted - Apr 08 2014 :  12:57:20  Show Profile  Reply
Hi dracola,

you can do simple green screen/chroma keying with SetTransparentColors method, but
prior to that, you must enable alpha channel.

However, deciding what color to choose for minColor and maxColor for such type of task may be a problem. If your background consists of single color (0, 255,0), then simply set minColor = maxColor = (0,255,0) and it will work.

For more sofisticated chroma keying, where you don't have single green color, but rather a range of "greenish" colors, I don't thing that SetTransparentColors method will yield
a desired result, especially because all colors in the range [minColor, maxColor] will have single alpha value (specified by the last parameter in function call).




Go to Top of Page

dracola

Argentina
37 Posts

Posted - Apr 09 2014 :  05:37:28  Show Profile  Reply
i'v tried

ImageEnView1.IO.LoadFromfile('c:\background.jpg');
ImageEnView1.EnableAlphaChannel:=TRUE;
ImageEnView1.Proc.SetTransparentColors(CreateRGB(255,240,170),CreateRGB(255,210,0), 0); //remove yellow background

but it's seem doesn't do anything
Go to Top of Page

spetric

Croatia
308 Posts

Posted - Apr 09 2014 :  06:18:23  Show Profile  Reply
Just add the line:

ImageEnView1->IEBitmap->AlphaChannel;

before line

ImageEnView1->EnableAlphaChannel = true;

This instruction will actually create/add alphaChannel to IEBitmap.
EnableAlphaChannel on ImageEnView actually only tells ImageEnView to take into account bitmap's alpha channel when image is displayed.
Go to Top of Page

dracola

Argentina
37 Posts

Posted - Apr 09 2014 :  07:48:05  Show Profile  Reply
thank's spetric for your help

i'v add to be like this, but it's seems still doesn't do anything

ImageEnView1.IO.LoadFromfile('c:\background.jpg');
ImageEnView1.IEBitmap.AlphaChannel;
ImageEnView1.EnableAlphaChannel:=TRUE;
ImageEnView1.Proc.SetTransparentColors(CreateRGB(255,240,170),CreateRGB(255,210,0), 0); //remove yellow background

may be if i add the image that i used if that helps

i want to make yellow background become transparent so i can add new layer for the background like beach or mountain picture ^_^

Go to Top of Page

w2m

USA
1990 Posts

Posted - Apr 09 2014 :  08:42:24  Show Profile  Reply
The yellow you are trying to make transparent is not all pure yellow. There are many shades of yellow in the image as I am sure you aware. You came pretty close to guessing the RGB values:
Min: CreateRGB(255,240,170)
Max: CreateRGB(255,210,0)

But the correct Min and Max RGB values are
Min: CreateRGB(234,170,1)
Max CreateRGB(255,234,129)

My "Select Similar Colors Demo" at http://www.imageen.com/ieforum/topic.asp?TOPIC_ID=1446 will reveal the yellow shades.

It is difficult to render a background with many different shades of yellow as transparent but my other demo "Make Selection Transparent Demo" shows you how to do this.

It works by calculating the minimum and maximum RGB color values so that the correct values are set with SetTransparentColors. It is nearly impossible to "guess" at the minimum and maximum color RGB values. As far as I know the only way to do this is by calculating the minimum and maximum RGB values for all the shades of yellow from all the pixels in the image.

Here is your photo rendered as transparent and saved as a png image with my demo:

This particular picture is quite difficult to deal with because there are about 200 shades of yellow in the image out of a palette of 255 colors.

This will render the yellow shades as transparent:
ImageEnView1.Proc.SetTransparentColors(CreateRGB(234,170,1),CreateRGB(255,234,129), 0);
  ImageEnView1.Update;

so if you use the correct RGB values the transparency will be rendered correctly.

William Miller
Adirondack Software & Graphics
Email: w2m@frontiernet.net
EBook: http://www.imageen.com/ebook/
Apprehend: http://www.frontiernet.net/~w2m/index.html
Custom ImageEn Development
Go to Top of Page

dracola

Argentina
37 Posts

Posted - Apr 09 2014 :  09:49:26  Show Profile  Reply
oh my gosh...shame on me...
i just used min & max color that you gave and viola it's work...

thank's a lot w2m for all your help & trouble
Go to Top of Page

w2m

USA
1990 Posts

Posted - Apr 09 2014 :  10:17:38  Show Profile  Reply
Do you have some way to pick the correct RGB colors that I am not aware of? How will you set the Min and Max for other images?

William Miller
Go to Top of Page

dracola

Argentina
37 Posts

Posted - Apr 09 2014 :  15:45:30  Show Profile  Reply
yeah, that the problem now how to get min & max from image background?
i'v tried your demo program, which i must select almost every similar color from pallete to get select all the background to get perfect result like your result image.
but how to determine optimal min & max color in a image?
Go to Top of Page

w2m

USA
1990 Posts

Posted - Apr 09 2014 :  15:49:45  Show Profile  Reply
There is no other known way to get the min and max that I know of, but if you select the colors correctly... it works perfectly regardless of how complex the background is. for many images you only have to select a couple of rows of colors with SHIFT-Click... you do not have to select each color individually.

William Miller
Adirondack Software & Graphics
Email: w2m@frontiernet.net
EBook: http://www.imageen.com/ebook/
Apprehend: http://www.frontiernet.net/~w2m/index.html
Custom ImageEn Development
Go to Top of Page

spetric

Croatia
308 Posts

Posted - Apr 10 2014 :  13:03:43  Show Profile  Reply
I made a mistake: SetTransparentColor method will actually create alpha channel,
so the line ImageEnView1->IEBitmap->AlphaChannel isn't necessary.

It's very interesting how this image came out very good, without border artifacts that usually comes when simple algorithms for removing background are used.

Go to Top of Page

w2m

USA
1990 Posts

Posted - Apr 10 2014 :  13:32:03  Show Profile  Reply
Spectric... Yes this is the best I have seen, although I must admit that for some images selecting all the background colors is not as easy as it should be when there are a lot of similar colors scattered in the 255 color palette. But even for moderately complex backgrounds it is relatively simple... If you select the correct background colors it returns a perfect result each time.

I wish I could figure out how to sort the colors then it would be simple matter of selecting the rows of the background color.

William Miller
Go to Top of Page

xequte

38615 Posts

Posted - Apr 10 2014 :  14:06:03  Show Profile  Reply
@Bill

> I wish I could figure out how to sort the colors then it would be simple matter of selecting the rows of the background color.

Sorry, I may have missed the point, but why not iterate all colors in a selection of the image calculating the minimum and maximum RGB values? (though naturally may have unexpected consequences if the color range is broad)

Nigel
Xequte Software
www.xequte.com
nigel@xequte.com
Go to Top of Page

spetric

Croatia
308 Posts

Posted - Apr 10 2014 :  14:13:29  Show Profile  Reply
Yes Will, it works good, however problem of border artifact comes when you have 24-bit image.

Here I find some discussion on this topic:
http://www.lac.inpe.br/JIPCookbook/6520-howto-chromakey.jsp

Regarding on palette sorting, it's a complex task. I have some palette functions in my prog. and I sort palette entries using luminance. Then I use binary search to find closest luminance, etc. But, luminance is sometimes not enough, because different hues may have equal luminosity.

So, for such kind of task, maybe it's better to sort palette entries according to color hue.

@xecute

>Sorry, I may have missed the point, but why not iterate all colors in a selection of the image calculating the minimum and maximum RGB values? (though naturally may have unexpected consequences if the color range is broad)

I use simple algorithm for such task. When iterating through colors
simply find difference (if green screen is examined) between green channel and max(r, b):


// loop through image pixels and set alpha channel
// threshold - value specified by user
gDiff = g - max(r,b);  
if (gDiff > threshold)
   alpha = 0;
else
   alpha = 255;    	


But, I still have border artifacts if background has a broad color range.
Go to Top of Page

w2m

USA
1990 Posts

Posted - Apr 10 2014 :  14:23:13  Show Profile  Reply
@Nigel,

That is what I am doing now, but for the yellow background Image shown earlier in this que there are about 200 shades of "yellow" among a palette of 255 that have to be selected and they are scattered all over the palette... If all the yellow hews were all together then selecting the "yellow" would be trivial.

The problem is not calculating the min and max values but how to display a 255 color palette sorted by Hew or similar color.

William Miller
Go to Top of Page

w2m

USA
1990 Posts

Posted - Apr 10 2014 :  14:28:21  Show Profile  Reply
@Spetric,

The problem is not with artifacts or setting the alphachannel... the problem is sorting the palette. So far I have not seen any artifacts at all when the colors are selected correctly.

Send me your most difficult image and I'll see how it does. So far I have not fond an image that produces poor results.



William Miller
Go to Top of Page

spetric

Croatia
308 Posts

Posted - Apr 10 2014 :  14:49:41  Show Profile  Reply
It seems I'm missing the point. Are we talking about full 24-bit image
or image reduced to 256 colors?

Here is an image I've worked with (found it on the web):
http://susmadik.com/wp-content/uploads/18.jpg

When simple algorithm is applied, there are always border artifacts.
I'm talking about 24-bit output image (plus alpha channel).
Go to Top of Page

xequte

38615 Posts

Posted - Apr 10 2014 :  18:22:05  Show Profile  Reply
@Bill: I'm not sure that there is any reasonable way to sort colours. If you were after a basic hue, such as yellow, you could quite easily create an algorithm that weighted the yellow channel the most, with a lesser weighting given equally to the red and green channels, but it would not work for abstract hues such as dark purple or aquamarine.

@Spectric: Yes, but if Bill has a method that works well in 256 colours, then you could easily use the output as a mask against full colour. Personally however, I am not sure there is an easy solution to this problem, as it is not only a question of colours, but also of boundaries. In your example image there are greens amongst the leaves of the same shade as those in the shadow of the children.



Nigel
Xequte Software
www.xequte.com
nigel@xequte.com
Go to Top of Page

w2m

USA
1990 Posts

Posted - Apr 10 2014 :  19:01:19  Show Profile  Reply
I tied to render your image as transparent. My demo could not do it because there were too many colors in non-transparent areas that were also in the transparent area as suggested by Nigel. As a result pixels that should not be transparent were rendered transparent.

This is the first image I have tried where it failed to produce good results. just a little bit simpler images (like the gird picture) always seems work quite well.

There may no way to render this picture transparent other than by doing it manually by editing the pixels, but even that may produce somewhat poor results.

I might add that the reason why I used 256 colors is because with a full color image who wants to take the time to select 16,000 similar colors.... It was a necessity to get this to work reasonably well.

William Miller
Go to Top of Page

dracola

Argentina
37 Posts

Posted - Apr 11 2014 :  03:33:52  Show Profile  Reply
is imageen have algoritm like chroma key? beside using imageen.Proc.SetTransparentColors?
Go to Top of Page
Page: of 2 Previous Topic Topic Next Topic  
Next Page
 New Topic  Reply to Topic
Jump To: