Author |
Topic |
dracola
Argentina
37 Posts |
Posted - Apr 08 2014 : 06:47:05
|
is imageen have proc like greenscreen? i have tried imageen.Proc.SetTransparentColors but not working. |
|
w2m
USA
1990 Posts |
|
spetric
Croatia
308 Posts |
Posted - Apr 08 2014 : 12:57:20
|
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).
|
|
|
dracola
Argentina
37 Posts |
Posted - Apr 09 2014 : 05:37:28
|
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
|
|
|
spetric
Croatia
308 Posts |
Posted - Apr 09 2014 : 06:18:23
|
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.
|
|
|
dracola
Argentina
37 Posts |
Posted - Apr 09 2014 : 07:48:05
|
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 ^_^
|
|
|
w2m
USA
1990 Posts |
Posted - Apr 09 2014 : 08:42:24
|
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 |
|
|
dracola
Argentina
37 Posts |
Posted - Apr 09 2014 : 09:49:26
|
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 |
|
|
w2m
USA
1990 Posts |
Posted - Apr 09 2014 : 10:17:38
|
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 |
|
|
dracola
Argentina
37 Posts |
Posted - Apr 09 2014 : 15:45:30
|
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? |
|
|
w2m
USA
1990 Posts |
Posted - Apr 09 2014 : 15:49:45
|
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 |
|
|
spetric
Croatia
308 Posts |
Posted - Apr 10 2014 : 13:03:43
|
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.
|
|
|
w2m
USA
1990 Posts |
Posted - Apr 10 2014 : 13:32:03
|
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 |
|
|
xequte
38613 Posts |
Posted - Apr 10 2014 : 14:06:03
|
@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
|
|
|
spetric
Croatia
308 Posts |
Posted - Apr 10 2014 : 14:13:29
|
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. |
|
|
w2m
USA
1990 Posts |
Posted - Apr 10 2014 : 14:23:13
|
@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 |
|
|
w2m
USA
1990 Posts |
Posted - Apr 10 2014 : 14:28:21
|
@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 |
|
|
spetric
Croatia
308 Posts |
Posted - Apr 10 2014 : 14:49:41
|
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). |
|
|
xequte
38613 Posts |
Posted - Apr 10 2014 : 18:22:05
|
@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
|
|
|
w2m
USA
1990 Posts |
Posted - Apr 10 2014 : 19:01:19
|
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 |
|
|
dracola
Argentina
37 Posts |
Posted - Apr 11 2014 : 03:33:52
|
is imageen have algoritm like chroma key? beside using imageen.Proc.SetTransparentColors? |
|
|
Topic |
|