I have a ppm file and I figured out how to mirror the image from the middle but I can't figure out how to horizontally flip it.
this is the code for the mirror function:
{R[x][y]=R[WIDTH-x][y];
G[x][y]=G[WIDTH-x][y];
B[x][y]=B[WIDTH-x][y];}}
the horizontal flip function should look almost the same as above. but achieve a flipped image.
Use System.Drawing.Bitmap
GetPixel()
SetPixel()
The MSDN Documentation for System.Drawing.Bitmap
Related
Currently, I am working on a real-time IRIS detection application.
I want to perform an invert operation to the frames taken from the web camera, like this:
I managed to get this line of code, but this is not giving the above results. Maybe parameters need to be changed, but I am not sure.
CvInvoke.cvThreshold(grayframeright, grayframeright, 160, 255.0, Emgu.CV.CvEnum.THRESH.CV_THRESH_BINARY_INV);
From the images above it feels that the second image is the negative of the first image(correct me if I am wrong),
The function you are using is a threshold function,i.e. will render everything as white if it falls between the specified color range and other wise it will render it as black.
To find the negative of an image you can use one of the following methods.
Taking the NOT of an image.
Image<Bgr, Byte> img2 = img1.Not();// imag1 can be a static image or your current captured frame
for more details you can refer the documentation here.
If you want to invert an image you can do the following:
Mat white = Mat::ones(grayframeright.rows, grayframeright.cols, grayframeright.type);
Mat dst = white - grayframeright;
Also note that pupil can be detected with OpenCV detector initialized with HAAR cascade for eyes that OpenCV code comes with.
I have program in which i want to do some graphic algorithms. I found some code snippets for C# that works on bitmaps. To change pixel or something like that do i have to convert image to bitmap first or is there some methods to change pixels in Image? Something like image1.SetPixel(29,201, color1); ?
You can use the WriteableBitmap class to create a bitmap whose pixels you can modify.
You can then set that Bitmap as the Source for an Image element.
http://books.google.co.uk/books?id=nYl7J7z3KssC&pg=PA416&lpg=PA416&dq=wpf+writeablebitmap&source=bl&ots=V533ojV65x&sig=KJeSje1WCXaS_MT78cR4PPZMFio&hl=en#v=onepage&q=wpf%20writeablebitmap&f=false
http://www.i-programmer.info/programming/wpf-workings/527-writeablebitmap.html?start=1
http://www.nerdparadise.com/tech/csharp/wpfimageediting/
There's a 3rd party library which can help working with WriteableBitmaps more natural i.e. SetPixel and GetPixel methods instead of having to calculate offsets to the pixel data in the buffer.
http://writeablebitmapex.codeplex.com/
I would like to be able to add an image to a live tile so that there is no stretching and the image looks normal. I am getting my images from the PhotoChooserTask, which contain images from the medialibrary. As of now I can successfully place an image on a live tile, but it is stretched and the aspect ratio is not correct. How would I be able to find the aspect ratio of the image and crop the image so that it ends up being a square with dimensions 173x173 with no streching? I have followed a couple tutorials found online but nothing seems to accomplish this the way I need it to.
I accomplished this by referencing Resize image for Live Tile - WriteableBitmapEx which proved to have the correct implementation.
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.
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