How to draw the gray 8 bits image acquired form camera device using direct2d - 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

Related

HTML5 canvas - make a mono mask efficiently without antialiasing

I am using pixel colour inspection to detect collisions. I know there are other ways to achieve this but this is my use case.
I draw a shape cloned from the main canvas on to a second canvas switching the fill and stroke colours to pur black. I then use getImageData() to get an array of pixel colours and inspect them - if I see black I have a collision with something.
However, some pixels are shades of grey because the second canvas is applying antialiasing to the shape. I want only black or transparent pixels.
How can I get the second canvas to be composed of either transparent or black only?
I have achieved this long in the past with Windows GDI via compositing/xor combinations etc. However, GDI did not always apply antialiasing. I guess the answer lies in globalCompositeOperation or filter but I cannot see what settings/filters or sequence to apply.
I appreciate I have not provided sample code but I am hoping that someone can throw me a bone and I'll work up a snippet here which might become a standard cut & paste for posterity from that.

Corrupted resized textures with Metal on Retina screens

I want to draw a series of textures into METAL view in order to present a complete image. On a regular screen, the images are presented on exactly 1:1 scale (Meaning a 100x100 pixels texture will be presented in a 100x100 pixels square)
Drawing it on a retina display, will actually give me a 200x200 square.
Now, there may be 2 different approaches:
1) Generate entire image into 100x100 square and let Metal View to upscale it to 200x200 square - It works.
2) Upscale each texture and generate image directly into 200x200 square. Why to take this approach? Because some of the textures (Like texts) are generated dynamically, and can be generated in a better resolution. Something impossible if you take the first approach.
Unfortunately, in this approach, some ugly square is visible around each texture.
I tried to play with sizes, clamp options etc, yet I could not find any solution.
Any help would be highly appreciated!
Image from regular screen
Image from retina screen
Found a solution. In Fragment shader, texture sampler was defined as:
constexpr sampler s = sampler(coord::normalized, address::repeat, filter::nearest);
instead of:
constexpr sampler s = sampler(coord::normalized, address::clamp_to_edge, filter::nearest);

There have any process to detect an image is a black&white image or a colored image?

I need to detect an image is a color image or black&white image. But don't understand what will be the process or there have any function to detect it. If there have no function to detect it then what will be the process?
Image file has mode, which tells if it is RGB, grayscale or B&W.
I assume you know that and you are trying to examine a RGB image to see if it only has black / white color. In this case you can calculate the histogram of the image in all R/G/B channels, the black and white will have two sharp peaks in all three channels.
Please use a image editing software like GIMP and experiment.

how to create a mask for a sprite or for a texture in libgdx

I am developing on libgdx for android and the thing is that I've used masks for my sprites before (not in libgdx) to set the surrounding of my sprites to be transparent so when I draw them to the screen they show the background and not a white rectangle, but I don't seem to find any way to do this in libdgx, how do you guys go about crating masks for your 2d sprites? Do I have to use OpenGL cause I don't know much about it if so can you tell me how? and also can I do it on a texture?
I just use PNG images for sprites with transparent pixels in them. These PNG images are packed to bigger PNG texture file with either Texture Packer or using Libgdx to make the texture.
You can use mesh like this http://code.google.com/p/libgdx/wiki/MeshColorTexture

CvBOX2D Processing

I've already got my ROI(CvBOX2D type) by series of contour processing, now I just want to focus on the image part within the ROI, e.g.: feed this part into another processing function, how can I do that? I know there is CvSetImageROI, but the type is CvRect, so I should convert CvBox2D to CvRect first? Or some way to apply a mask on it with the area outside the box set to 0?
Thanks in advance!
Only axis aligned ROIs are directly supported in OpenCV (CvRect or IplROI). This is because they allow direct access to the image memory buffer.
There are 2 ways to go about working on a non-axis aligned ROI in OpenCV. Neither of them is as efficient as using axis-aligned ROIs.
Rotate your image, or bounding box, so that your ROI is now axis aligned in the resulting rotated image.
Note: the rotation will slightly blur your image.
Use a mask: Draw your ROI as a white rectangle on a black BG the same size as the image, and give your processing functions this mask as the additional parameter.
Note: not all functions support masks.
I would recommend option 1 if you really must stay within the exact bounds of your ROI. Otherwise, just use the bounding rect.
Use c++ api of opencv. seriously. do it.
cv::Rect roi = cv::RotatedRect(box).boundingRect();
Mat_<type> working_area(original_mat, roi);
// now operate on working_area
Note: this will operate on the bounding rect. I didn't find information on how to create a mask out of rotatedrect. Probably you have to do it by hand in a scanline fashion.

Resources