Log in

View Full Version : Process only rectangle in image? [SOLVED]


AviUser
24th August 2010, 20:24
Hi,

My video has a "bright" line on the right edge of the video throughout the whole video. See this image (note part of image was cut out): [link removed]
I want to darken only this line, but using Crop and Overlay seems very inefficient.

Does anyone know how to do it more elegantly?

Thanks in advance!

IanB
24th August 2010, 23:08
Top=Crop(0,0, 0,32)
Mid=Crop(0,32, 0,-32)
Bot=Crop(0,Height()-32, 0,0)

Left=Mid.Crop(0,0 32,0)
Cent=Mid.Crop(32,0, -32,0)
Right=Mid.Crop(Mid.Width()-32,0, 0,0)

NewCent=Cent.Filter(...) # process as required

NewMid=StackHorizontal(Left, NewCent, Right)
StackVertical(Top, NewMid, Bot)
Of course choose numbers other than 32 that suit your image.

And of course you could process Top, Bot, Left and/or Right if you want to leave the middle and do the edges.

Crop() is a zero cost filter, it just does pointer arithmetic as the graph is compiled.

The Stack*() filters cost 1 Bitblt, i.e. the standard minimal not in place filter processing cost.

poisondeathray
24th August 2010, 23:37
Sorry for thread hijack, but it's a related question:

How would you do a feathered overlay , such that the edge transition isn't so abrupt?

I read this thread: and there is a way using alpha channel and bluring mask edge, but just wondering if there is another approach?
http://forum.doom9.org/showthread.php?t=155937

and AviUser - if you post your images at a 3rd party site, you don't have to wait for mod approval (e.g. imageshack.us, imagebam, tinypic etc...)

AviUser
24th August 2010, 23:47
Thanks for the StackHorizontal function, it works really good. However, the edge transition is still pretty abrupt. How can I "smooth" that boundary?
Also, how can I use Tweak on an image with dimensions like 7x8 (it says I cant use RGB data)? Do I need to make a fake extra 1 pixel line and crop it off again...?

Also, I updated the image link.

poisondeathray
24th August 2010, 23:58
I can answer the tweak question . It only works on YUV data . So you would have to ConvertToYV12() or ConvertToYUY2() first , and if your source is interlaced (it might from your posted image, not sure), don't forget interlaced=true .

And IIRC correctly, you cannot freely crop interlaced YV12 material , it has to be in multiples of 4 (I think) .

Are you doing this for actual video or on still images ?

AviUser
25th August 2010, 00:17
Thanks. Actual video.

Both of us have the same question now about feathered overlay I guess.

poisondeathray
25th August 2010, 00:19
But is your video interlaced, and what colorspace ?

AviUser
25th August 2010, 00:41
The video is already deinterlaced before I attempt to darken the line and it is in YV12 color space.
Should I deinterlace after darkening the line?

IanB
25th August 2010, 09:01
For feathered edge transitions, Overlay() or Layer() with an appropriate mask is the way forward.

If maximum efficiency is the goal, then the hard slice and stack option can be used to reduce the size of the image actually being processed.

e.g....
Left=Crop(0,0 40,0)
Cent=Crop(40,0, -40,0)
Right=Crop(Width()-40,0, 0,0)

FixLeft=Left.Filter(...) # process as required
MaskLeft=ImageSource("MaskLeft.ebmp", End=0).Loop(FrameCount()) # White=Opaque, use FixLeft pixels
Left=Left.Overlay(FixLeft, Mask=MaskLeft) # Feathered blend at boundary according to mask

FixRight=Right.Filter(...) # process as required
MaskRight=ImageSource("MaskRight.ebmp", End=0).Loop(FrameCount()) # White=Opaque, use FixRight pixels
Right=Right.Overlay(FixLeft, Mask=MaskRight) # Feathered blend at boundary according to mask

StackHorizontal(Left, Cent, Right)If it mattered, the heavy lifting is only done on 2 by 40 pixel wide strips. The main centre pixels remain unprocessed and fast. Unless Filter(...) is heavy duty and I suspect it will just be a Tweak() or such, this is really just a thought exercise. Tweak or Overlay() are not really that heavy duty.

AviUser
25th August 2010, 17:41
Thanks, I ended up using "the hard slice and stack option" and Tweaking the line to be less bright. I also Blur()ed the edge again using the slicing option.

It looks kind of strange but its better than before.

Thanks all for your replies!