How to show a YCbCr image using Emgu in C#? - c#

I got a bitmap as a source;
I created a Emgu image with Image<Bgr,Byte> img = new Image<Bgr,Byte>(bmp);
I converted it to a YCbCr image using Image<Ycc,Byte> YCB = img.Convert<Ycc,Byte>();
I dragged a imagebox from the toolbox and assigned it with YCB -----> imagebox1.Image=YCB;
but the result shows the image in RGB format just like source bitmap
I don't understand where went wrong
Could someone give me some clues?

Have you made any alterations to YCB? If you simply display it then it will look identical to the original.
If you right click on your imagebox when running your program and select property it will tell you the type of image and show you the data held within the YCB image this should be different from your original. Alternatively just show 1 channel of your image matrix so for your BGR show the blue colour this will obviously be displayed as a single colour grayscale image. Now for the YCB show the Luma channel again this will be displayed as a single colour grayscale image. You will notice a slight change between them as the luma represents the luminance of all 3 colour spectrums.
CvInvoke.cvShowImage("Blue", img [0]);
CvInvoke.cvShowImage("Luma", YCB[0]);
If you want to see a greater difference multiply the Luma by 2 and you have a completely different image.
YCB[0] *= 2;
CvInvoke.cvShowImage("Luma Change", YCB);
The CvInvoke.cvShowImage() method is a great tool for debugging your code and seeing what your code is doing to images step by step.
For the benefits of others Ycc is YCbCr colour space: http://en.wikipedia.org/wiki/YCbCr
Cheers,
Chris

Related

C# white or black unwanted pixels appear in the image

I am new to C#, I am using Visual Studo 2010, I have an image that needs to be displayed on a picturebox.
I tried many different methods. All the methods results in some unwanted pixels to appear along with image.
I have tried
picturebox.Image = Image.FromFile("bird.png");
result->
the image is displayed but with the stray white/black pixels at random places.
I also tried creating a bitmap of same size and drawing the image onto the bitmap and then assigning the bitmap to the picture box.Image. Still those unwanted pixels are visible.
I have tried clearing the picture box image (filling it with white or transparent) and then assigning the image, still same error occurs.
PS: this doesn't happen for all the images only certain images show this behaviour.
any help would be great
Code:
Image org = Bitmap.FromFile("bird.png");
Bitmap final = new Bitmap(org.Width,org.Height);
using (Graphics g = Graphics.FromImage(final))
{
g.DrawImage(org,0,0,GraphicsUnit.Pixel);
}
picturebox.Image = final;
if i use final.save("picture.png"). The "picuture.png" does not have that wrong pixels, it happens only when i use picture box to display it.
Please find the images attached defect orginal
PS: its not because of different fileformat (orginal and defect)
It was an TransperancyKey issue resolved by setting it to Default.

How to convert a Grey Scale image to RGB in C#?

How to convert a Grey scale image to RGB format? I have added Aforge library too but unable to define thresholds for coloring.
I'm not understand clearly what do you mean under Convert gray scale image to RGB and suppose that you are trying to revive colors. Unfortunately it's not possible to do it precisely. I mean you can revive colors from grayscale image but this colors would not exactly the colors was befor transforming to gray.
Standard transformation from color to grayscale assumes that every pixel of image transformed by formula:
G(R,G,B) = 0.299*R + 0.587*G + 0.114*B
where R, G and B are RGB values of pixel
As you understand reverse that transformation may have many different results. Look at http://en.wikipedia.org/wiki/Grayscale for more info.
You also may take a look at this project. It implements solution that makes attempt to revitalize colors from grayscale image. But again, take im mind that this colors would not be an original colors
Anton has a good point which is the resulting colored image will not have the colors in the original image.
This is why coloring a grayscale image is called false coloring I believe.
For images with palette, you can just replace the palette.
For images without palettes, you will have to define a formula to work with.
In our application, we used sdk called leadtools that had functions for coloring gray images and we find it to be very helpful.
Using Aforge do this:
var filter = new GrayscaleToRGB();
var RGBBitmap = filter.Apply(AForge.Imaging.Image.Convert16bppTo8bpp(bitmap));
(if you already have a 8bpp bitmap you can leave out the conversion)
GrayscaleToRGB is in AForge.Imaging.Filters

changing hue and saturation in pixel level

I'm working on a image processing project where i need to change the color of the object. For that i have performed a threshold operation and obtained object pixels as shown in the image. After that i have applied the various colors to object using setPixel method in c#. But this method destroy all the characteristics of the images. But actually i need something like the bottom images. I obtained the them by editing in Adobe Photoshop by changing hue and saturation. can you guys make any suggestions how do this.
code example appreciated, thanks in advance.
Original Image
Threshold Image
Color Applied Image
Required Image
Obtain the hue, saturation, and brightness of every pixel from the RGB values (RGB<->HSV). Then play with them, and convert the image back to RGB.

Image Modification (cropping and de-skewing) in C#

With a mobile device I take a picture of a flat light object on a dark surface. (for instance a coupon clipped out of a newspaper).
The image is then run through a brightness/contrast filter. If it is too dark, vital components are left out. If it is too bright, the writing on the coupon is lost.
This image is then converted into a bitonal image. Any pixel that is 50% or more dark is converted to black, everything else is white. (done)
I am left with a skewed bitonal image (think of a white trapezoid inside a larger rectangle with a black background).
I need to figure out how to crop the image - which when it's on a black background is easier than when it's on a white background. Then, I have to de-skew the image so it is rectangular instead of trapezoidal, while attempting to preserve aspect.
The end result should be a nicely cropped, bitonal, readable image of the coupon.
To crop your image, you can use the LockBits method and scan through all your pixels to find the first pixel with content from the top, left, right and bottom, respectively. How to use LockBits is described nicely here: https://web.archive.org/web/20141229164101/http://bobpowell.net/lockingbits.aspx
Assuming your image is not rotated, and that the skewing comes from the camera held at an angle against the table where the coupon is being photographed, you should now have a skewed image of the coupon, fitting perfectly within the bounds of the cropped bitmap. You should also know the four corners of the trapezoid.
"Undistorting" an image is not as easy as you might think though. However, good people have solved this problem and you can probably port their code to your own use. Here is a link I used to explore this problem in a similar case some time ago:
http://ryoushin.com/cmerighi/en-US/2007-10-29_61/Image_Distortion_Enhancements
I also have some code stored somewhere if you can't make any sense of what you find.

C# Using Emgu to crop an image by pixel color

Hey i was wondering if anyone had any insight on how to crop an image by pixel color using the Emgu Wrapper.
I have it already turn the image grayscale for processing and all the image that i don't need is black. Is there any way to crop these pixels out? Now I'm not talking about making them transparent, i physically want to make the output image smaller.
Thanks!
It's really simple... all you have to do is set your input image ROI property on the non black pixels using a rectangle, then you create the destination image with image equals to ROI size and use Copy() method on your input image choosing as destination your dest image.
HTH, Luca

Categories

Resources