How to insert cursor image in YUV(NV12) buffer? - image

i have captured screen with Intel Capture in NV12(YUV) format. Intel capture does not capture Mouse cursor.
So i have to include cursor image in Intel captured yuv buffer.
Is it possible to edit(include) cursor image in yuv buffer ?
Guide me this.
Thanks in advance.

You can look how image is stored in NV12 (http://www.fourcc.org/yuv.php#NV12)
YUV 4:2:0 image with a plane of 8 bit Y samples followed by an interleaved U/V plane containing 8 bit 2x2 subsampled colour difference samples.
You can try this:
Convert your cursor to YUV: https://en.wikipedia.org/wiki/YUV#Conversion_to.2Ffrom_RGB
Add cursor to frame. Y plane of the cursor to Y plane of the frame, the same with UV.
Also you can convert frame to RGB and insert cursor in RGB colorspace, but it is slowly.

Related

ffmpeg How does the blend filter work

I have small project which uses blend filter of FFmpeg library.
I read the examples of this document
https://ffmpeg.org/ffmpeg-filters.html#blend_002c-tblend
But I'm not clearly understand about it.
X, Y : the coordinates of the current sample
W, H : the width and height of currently filtered plane
What are the sample and filtered plane?
Is there any document about these things.
In the context of an image, a sample refers to an individual pixel. However, a pixel usually has multiple components, like RGB (red, green and blue) or YUV (luma and two chroma units). So 'sample' here refers to the individual stores of value, i.e. a Magenta RGB pixel is defined by three samples (255,0,255).
Pixels of a frame can be stored packed (R1G1B1R2G2B2..) or planar ([R1R2...RN][G1G2..GN][B1B2..BN]). The blend filter works on planar formats only.
In YUV format images, the UV is typically subsampled and so the width and height of UV planes is lower than that of the luma plane.

matlab render graphical objects to a bitmap in memory

This is supposed to be very simple I think but I can't get it right...
I plot several graphical objects in a figure and now I want a bitmap of the figure, that maintains the position on the objects and the dimensions of the figure.
To give a very simple example, if I plot 2 points in coordinates (0,0) and (200,200) I expect the rendering to output a matrix of size (200,200) where pixels (0,0) and (200,200) have a gray level of 255 and the rest of the pixels are zeroed (this is in case of a 8-bit per pixel grayscale though 3I prefer a color bitmap that will reflect the colors of the objects as appear in the original figure)
Thanks
To answer my own question, this is what I did to render a figure with graphical objects to a bitmap in memory and keep it in scale: I used getFrame and then resized the result to the size of the axes. Here goes:
% plot stuff on the current axes, then...
set(gca, 'ydir', 'reverse');
xLim = get(gca, 'XLim');
yLim = get(gca, 'YLim');
rendered = getframe(gca);
imageMat = imresize(rendered.cdata, [floor(yLim(2)), floor(xLim(2))]);
Here the image is sampled twice which is both inefficient in terms of processing time and gives a somewhat degraded image. For my purposes it's ok but still a single-sample solution would be nice...

How to draw the gray 8 bits image acquired form camera device using direct2d

I can not find the correct DXGI_FORMAT_* to represent a gray 8 bits image. Can anybody suggest a proper way drawing gray image using direct2d.
DXGI_FORMAT_A8_UNorm or DXGI_FORMAT_R8_UNORM

Encode 256 Palletized bitmaps to h264 using libav

Am converting 32 bpp bitmap to 8bpp with 256 color pallete, this image i want to encode using h264 and send it over socket. And on the other end decode the frame and display it on my UI.
From Encoder, side:
Capture 32 bpp image.
Quantize the image to 8bpp with 256 color pallete.
Sws_scale the image from PIX_FMT_GRAY8 to YUV420P.
Encode it with h264 and send it over socket.
From Decoder, side.
Receive image.
Decode image.
Sws_scale from YUV420P to PIX_FMT_GRAY8
And display it on UI along with palette information(Sent from Encoder over socket).
When the above steps are followed, i get a totally distorted image. And when i dont use the color palette i get a black and white image.
Am not not clear how to encode the 8bpp 256 palette bitmaps using h264 and decode them accordingly. Please help me regarding this.
Am working with C++ on windows platform.
Thanks in advance,
Paul.
h.264 is not (by default) a lossless codec. So you will not get the exact color out that you put in on a pixel by pixel basis. In YUV the Y plan is luminance (black and white) and the UV planes are chroma. So your UV planes are empty here. The Y plane is compressed in a lossy fashion. so you may have a pallet that looks like 0=black 1=red 2=green ... 255=white. And you put in a 2 pixel. During the compression, to remove complexity in the image to reduce file size, the 2 may become a 1. In a black and white image you will not notice the difference. But when you apply your pallet, you green pixel just turned red.
You either need to use a a lossless codec, or encode your 256 color image to a YUV color image. Then post decode re-qunatize the colors back to your desired pallet by finding the closest color or each decoded pixel.

View pixel intensities of an image

How to view the pixel intensities of an image in matlab by moving the mouse pointer over the image?
I used:
imshow(imread('image.jpg'));
But there is no option to view the pixel intensities of each pixel in the image.
For example,
In MS-paint, while moving the mouse pointer
over the image we can see the location of
the pixel such as (20, 117) at the status bar.
But I need to see the pixel intensity instead.
Is there any other option to view it. Or I need to code to view it?
One other option which is more interactive is
imtool(imread('image.jpg')); % For GrayScale Image
imtool(rgb2gray(imread('image.jpg'))); % For RGB Image
If you want to create an intensity map, you can use MATLAB's rgb2gray. This will convert the n-by-m-by-3 RGB array you got from imread to an n-by-m matrix which contains the pixel intensities.
You can then point the interactive data cursor to this intensity matrix for the current mouse coordinates.
you have impixelinfo and impixelinfoval for showing interactive information.

Resources