How to check if bunch of jpg files are black with C# - c#

So I have a program that scans cameras from multiple sources and takes a thumbnail of their view at a certain time and saves them as jpg's.
I would like to now scan these through my C# program and check if any of the created jpg files are completely black (either completely obstructed, or no signal in this case).
I am wondering what would be the best way of solving this problem. Not a color depth issue.
Thanks!

Use the GetPixel(x,y) function to check color at x,y location. You can iterate through the whole image and if they're all black then it's black. You can also check if majority of pixels are gray / black - if so then it's probably a very dim image.

Load picture.
Go through all pixels and check their RGB value.
If you find all below a certain threshhold - assume picture is black.
Beware: you should likely ignore single pixels not being black. Sensors are not perfect. Stuck pixels are a known phenomenon.

Related

Determine boundaries of sheet music for cropping

I have thousands of images of sheet music, in 4:3 aspect ratio, that I want to crop to something closer to 16:9. The images have a lot of whitespace, so at least I want to cut that away.
All the images are different, even the margins aren't always the same.
What kind of algorithm should I use in C# to detect the edges of the staves, so I can determine where to crop the image?
(The green box is where I'd want to crop this image)
I've tried looping through all the pixels, that seems to work, but is extremely inefficient.
Is there a better way?

Emgu CV - ignore a color while matching template

I'm using Image class and it's MatchTemplate method in Emgu CV to detect pattern in pictures. So, my pictures are black-white (with 256 gray variants) and I have to search for white templates, but how do I store them? If I'm using .png with only 2 colors: white for pattern and black for background - then MatchTemplate method considers the background part of template (and that's ruining the results). What color I have to use for background in patterns?
UPD: Images added.
Pattern (only white triangle needed):
Image example (a simple one):
Detection (white square is what I get, red one - what I need):
Please read this:
http://docs.opencv.org/2.4/modules/imgproc/doc/object_detection.html?highlight=matchtemplate#matchtemplate
You obviously don't know how matchTemplate works.
You cannot simply pick one colour for the background to be ignored. The algorithm always calculates some difference measure between template and some image region. Unless image and template background are the same you will always have an influence.
If you want to "ignore" the background you would have to replace the background by the image region for every iteration so the difference of backgrounds becomes 0 or at least the same for every pixel. This doesn't sound very efficient.
Provide input images and template examples. There is most likely a better solution for your problem.
You should probably modify your template image by removing the four black sides, which leaves only the white triangle and the black one. That should help you get your desired result.

From picture units to real world units

I need an optimal solution with a program I am working on. The program should take an image(black and white only) with some single black lined objects, like star, circle, rectangle and etc. After, a program should find a location of each black point on it and will track it. By this I according to those location I will make some computations to make my stepper mottor move accordingly. Imagine that there is marker and white board, and I want the picture on my pc to be drawn on whiteboard, by specifying the size .
I don't know, maybe there are some other ways beside the image, and what units is better, pixel based or ....?need some suggestions and recomendations.
Appreciate
With printing, scanning and monitors, there is the term DPI (Dot-Per-Inch), this is what you need to inspect to determine the real world size of an image. Compare the DPI of the device, by the number of pixels in your image.
Note, DPI is represented in dots per SQUARE inch.
I don't know how to do that with C# , but you can OpenCV and it wrapper for c# Emgu, you can read the image that you have and convert it to YCbCr color model and, you can you the contours function or minmaxloc function .

Bitmaps in WPF - give watermarking effect and then recover images individually

I am working on a project where I need to play with two bitmaps. I am putting them in a grid one over the other with reduced opacity (to give a watermark effect).
I am rendering the grid to a bitmap using RenderTargetBitmap and saving the bitmap to a file.
Now my requirement is to load the rendered bitmap again and recover the original pictures separately. Is there any way to recover the original images again. I am not able to think any algorithm to implement this.
My aim is to give a watermarking effect and then recover the images individually.
No. The information is lost during "flattening" of the image.
You need to save both images and information about their properties (position, opacity) into single file. And restore it on load.
If your goal is to simulate watermarking and allow later 'dewatermarking', then assuming that you have your watermarking bitmap present at decoding time, you probably can do that. Sure you cannot use your initial approach - just simple merging of two layers is not reversible.
You need to use some reversible transformation, like rotating source image pixel RGB values vector, using watermark image pixel RGB values as parameters. While dewatermarking you just use negative values from watermark image.
Well, RGB vector is not ideal - you can go out of RGB space while rotating it. Probably you can find color space (or some other transformation in RGB space), better suited to your goal.
(English is not my first or even second language, thereby I apologize if you can't understand my idea - just ask over.)
Why don't you try to make it two layers of bitmap?
i wonder if you can use TIFF format, where you can store multiple images. that way on display you can choose to show with/without watermark.

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.

Categories

Resources