imaging interview questions
Top imaging frequently asked interview questions
In my C# (3.5) application I need to get the average color values for the red, green and blue channels of a bitmap. Preferably without using an external library. Can this be done? If so, how? Thanks in advance.
Trying to make things a little more precise: Each pixel in the bitmap has a certain RGB color value. I'd like to get the average RGB values for all pixels in the image.
Source: (StackOverflow)
Group 3 compress has 2 variations (Group 3 1D and Group 3 2D). When saving an image in Tiff format, there is only one option for Group 3 in the EncoderValue enumeration. Is there a separate parameter that controls this?
Source: (StackOverflow)
Trying to create a transparent gif with PIL. So far I have this:
from PIL import Image
img = Image.new('RGBA', (100, 100), (255, 0, 0, 0))
img.save("test.gif", "GIF", transparency=0)
Everything I've found so far refers to manipulating an existing image to adjust it's transparency settings or overlaying a transparent image onto another. I merely want to create a transparent GIF (to then draw onto).
Source: (StackOverflow)
I'm using pygame (1.9.0rc3, though this also happens in 1.8.1) to create a heatmap. To build the heatmap, I use a small, 24-bit 11x11px dot PNG image with a white background and a very low-opacity grey dot that stops exactly at the edges:

The area around the dot is perfect white, #ffffff, as it should be. However, when I use pygame to blit the image multiple times to a new surface using BLEND_MULT, a grey square appears, as though the dot background wasn't perfect white, which doesn't make sense.
The following code, plus included images, can reproduce this:
import os
import numpy
import pygame
os.environ['SDL_VIDEODRIVER'] = 'dummy'
pygame.display.init()
pygame.display.set_mode((1,1), 0, 32)
dot_image = pygame.image.load('dot.png').convert_alpha()
surf = pygame.Surface((100, 100), 0, 32)
surf.fill((255, 255, 255))
surf = surf.convert_alpha()
for i in range(50):
surf.blit(dot_image, (20, 40), None, pygame.BLEND_MULT)
for i in range(100):
surf.blit(dot_image, (60, 40), None, pygame.BLEND_MULT)
pygame.image.save(surf, 'result.png')
When you run the code, you will get the following image:

Is there a reason this happens? How can I work around it?
Source: (StackOverflow)
Having spent a bunch of time recently doing 2D work that involves pixel manipulation of bitmaps and blending/compositing, I've run up against the limits of my own understanding with respect to colorspaces, non-RGB color worlds, etc.
I'd like to go back to basics and learn how all this stuff actually works, so that I'm not shooting in the dark next time I need to think about how to set up a blend function, and I know how to play with color palettes, etc.
Any pointers for good places to start on the path? Online references good, actual books that are clearly written are better. (Not looking for something that's just piles of equations, but can follow mathy stuff if it's not too terse.)
Thanks!
Source: (StackOverflow)
I am basically processing bar codes with an open source software. But the tool sometimes fails detecting no bar code at all.
So I want to myself check wether the image was really blank or it contains some sort of bar code.
My images are produced through scanning and they only contain a bar code (if they are not blank) and some noise images produced by the scanning. So my problem could be even down to checking if the image contains a significant amount of concentrated black pixels to differentiate it from white space images with noise.
I have checked this SO question, but the suggestion was to use "probabilistic Hough line transform" which I found a little bit an overkill for my situation.
I have also checked out this but it has unsafe code.
I am looking for a managed C# solution.
Source: (StackOverflow)
I'm looking for ways to determine the quality of a photography (jpg). The first thing that came into my mind was to compare the file-size to the amount of pixel stored within. Are there any other ways, for example to check the amount of noise in a jpg? Does anyone have a good reading link on this topic or any experience? By the way, the project I'm working on is written in C# (.net 3.5) and I use the Aurigma Graphics Mill for image processing.
Thanks in advance!
Source: (StackOverflow)
I am creating images using PIL that contain numerous exactly placed text strings. My first attempt was to convert pixel fonts into the pil-compatible format as described here. For example, I download the Silksreen font and convert it:
otf2bdf -p 8pt -o fonts/slkscr.bdf fonts/slkscr.ttf
pilfont.py fonts/slkscr.bdf
I can then use the font in PIL like so:
import Image, ImageDraw, os, sys, ImageFont
im = Image.new("RGB", (40,10))
draw = ImageDraw.Draw(im)
fn = ImageFont.load('fonts/slkscr.pil')
draw.text((0,0), "Hello", font=fn)
del draw
# write to stdout
im.save(sys.stdout, "PNG")
However, the resulting image (
) does not reflect what the font should look like.
What procedure should I be using to convert and use pixel fonts so that they render as intended?
Thanks in advance.
Source: (StackOverflow)
I'm having trouble drawing multilingual text using PIL. Let's say I want to draw text - "ひらがな - Hiragana, 히라가나". But PIL's ImageDraw.text() function takes only one font at a time, so I cannot draw this text correctly, because it requires English, Japanese, and Korean fonts all together.
So far, I had no luck finding a simple solution like passing multiple fonts to PIL, so that it can choose appropriate font for each Unicode character (Like modern SDK or web browsers do).
What I'm thinking is, I should iterate over each character, and determine which font to use for each character by myself. But I can't help thinking that there must be an easier way to do this.
Am I going in the right direction? Isn't there an easier way?
PS) It's OK to use another language or another imaging library if there's a much better solution.
Source: (StackOverflow)
I am getting the following Exception at ProcessImage(bitmap1, bitmap2)
;
Unsupported Pixel Format of source or template image
and this is my code:
public static double FindComparisonRatioBetweenImages(
System.Drawing.Image one, System.Drawing.Image two)
{
Bitmap bitmap1 = new Bitmap(one);
Bitmap bitmap2 = new Bitmap(two);
ExhaustiveTemplateMatching tm = new ExhaustiveTemplateMatching(0);
TemplateMatch[] matchings = null;
matchings = tm.ProcessImage(bitmap1, bitmap2); // Exception occurs here!
return matchings[0].Similarity;
}
I have also passed managedImage
from the below code into the method, but it still gives error:
UnmanagedImage unmanagedImageA = UnmanagedImage.FromManagedImage(bitmap1);
Bitmap managedImageA = unmanagedImageA.ToManagedImage();
UnmanagedImage unmanagedImageB = UnmanagedImage.FromManagedImage(bitmap2);
Bitmap managedImageB = unmanagedImageB.ToManagedImage();
- I have passed Images randomly from my computer, they all give exception.
- I have passed Blank Image edited in paint into the method,it still give exception.
- Also checked, jpeg, png, bmp formats, nothing work.
Source: (StackOverflow)
I'm trying to set up a C# application which uses TWAIN example from
http://www.codeproject.com/KB/dotnet/twaindotnet.aspx
This works fine except that I need to cast Form to IMessageFilter
and
call
IMessageFilter.PreFilterMessage()
to catch TWAIN callbacks.
Also I need to start this filtering by calling
Application.AddMessageFilter();
Is there a way to do same thing in WPF Window? (To add message filter and catch TWAIN callbacks).
Another totally high level question:
Does anybody know about alternative C# TWAIN libraries\wrappers?
Thank you.
Source: (StackOverflow)
Are there any OCR engines designed for identifying text in screen-captured images rather than scanned text? I have a project where I need to retrieve and identify text in an application, and none of the OCR engines I've tried so far have faired well with screenshots.
Ideally the engine should work well with color and with background noise, although I can make some allowances if nothing like that is available.
It will need to be .NET compatible; either written in .NET or having a .NET-callable API.
Source: (StackOverflow)
What do you recommend for quickly creating images for testing a software product (that needs hardware access - full USB port access)? Does virtualization cover this? I need to be able to quickly re-image the system to test from scratch again, and need good options for Windows and Mac OS.
Source: (StackOverflow)
I am making a little family photo album, with the intention to maybe open it to other people to store images later.
I upload the images to ~\images\, then resize them 3 times (Normal view ... thumbnail and a tiny version) and move them to ~\images\thumbs, ~\images\normal, ~\images\tiny and then move the original to ~\images\original.
If a user knows a file name, they can just goto http://mysite.com/images/normal/filename.jpg for direct access.
I'd prefer that not to be available to them.
So, is there a way to change the ImageUrl of the asp:Image control, to rather read from a non-accessable folder? And would this be a performance hit? I'm thinking something like (Not sure if it's possible) reading the image into s Steam, and somehow setting the ImageUrl or what ever, to read from the stream?
Hope you can assist.
Source: (StackOverflow)
In my project, I'm using (uncompressed 16-bit grayscale) gigapixel images which come from a high resolution scanner for measurement purposes. Since these bitmaps can not be loaded in memory (mainly due to memory fragmentation) I'm using tiles (and tiled TIFF on disc). (see StackOverflow topic on this)
I need to implement panning/zooming in a way like Google Maps or DeepZoom. I have to apply image processing on the fly before presenting it on screen, so I can not use a precooked library which directly accesses an image file. For zooming I intend to keep a multi-resolution image in my file (pyramid storage). The most useful steps seem to be +200%, 50% and show all.
My code base is currently C# and .NET 3.5. Currently I assume Forms type, unless WPF gives me great advantage in this area. I have got a method which can return any (processed) part of the underlying image.
Specific issues:
- hints or references on how to implement this pan/zoom with on-demand generation of image parts
- any code which could be used as a basis (preferably commercial or LGPL/BSD like licenses)
- can DeepZoom be used for this (i.e. is there a way that I can provide a function to provide a tile at the right resulution for the current zoom level?) ( I need to have pixel accurate addressing still)
Source: (StackOverflow)