I have huge images (1.800MP # 8bit or 16bit), all grayscale, no alpha, transparency or other stuff.
They may come as png, tiff, bmp, or even jpeg, so I need an image library to handle the reading, decompression and stuff.
After this, I just want to get an array with the grayscale pixel values out - preferrably 2d, but 1d is also alright. It also may be ushort all the time, even for the 8bit images.
I tried using the buid-int BitmapImage of C# - no luck, just throws exceptions for images this large.
Any other libraries that can give me the grayscale values, without hassle?
It will be faster if you use simple FileReader to read the content and generate your own array rather then looking for a library.
Customers upload image files, typically logos, to a web site, and I would like to be able to identify which colours the images contain.
I have kindof given up on bitmap images, since the anti aliasing introduces so many variations of each colour, but for vector images (eps, svg, ai to mention a few that could occur) I want to believe it should be doable.
The ideal solution would enable me to produce a list of colours which the user can verify; "Your image contains 3 colours: 111c, 222c and 333c, are these the colours you would like to use for printing?"
I am using Magick.net and C#. I am able to read the files into "MagickImage" instances, but I am lost on how to proceed in identifying the colours.
Let's say you start with this image, which is made from random colours then reduced down to just 18 colours:
convert -size 256x256 xc:black +noise random -colors 18 image.png
Now, you can get a list of the colours like this:
convert image.png -unique-colors -depth 8 txt:
Sample Output
# ImageMagick pixel enumeration: 18,1,65535,srgb
0,0: (7967,24415,7967) #1F5F1F srgb(31,95,31)
1,0: (24415,24672,8481) #5F6021 srgb(95,96,33)
2,0: (16191,12336,16448) #3F3040 srgb(63,48,64)
3,0: (8224,8224,24158) #20205E srgb(32,32,94)
4,0: (24672,24415,24415) #605F5F srgb(96,95,95)
5,0: (49344,16191,16448) #C03F40 srgb(192,63,64)
6,0: (16448,46260,13878) #40B436 srgb(64,180,54)
7,0: (8224,57311,24415) #20DF5F srgb(32,223,95)
8,0: (24415,57568,24415) #5FE05F srgb(95,224,95)
9,0: (49087,49344,16448) #BFC040 srgb(191,192,64)
10,0: (13364,16448,46517) #3440B5 srgb(52,64,181)
11,0: (24415,8224,57311) #5F20DF srgb(95,32,223)
12,0: (24415,24415,57054) #5F5FDE srgb(95,95,222)
13,0: (40863,24672,40863) #9F609F srgb(159,96,159)
14,0: (50372,15163,50115) #C43BC3 srgb(196,59,195)
15,0: (16448,49087,49344) #40BFC0 srgb(64,191,192)
16,0: (41120,40863,41120) #A09FA0 srgb(160,159,160)
17,0: (50372,50372,50372) #C4C4C4 grey77
And maybe you would like a swatch too:
convert image.png -unique-colors -scale 400x40 swatch.png
I m new in image processing field. I have worked with bmp images but currently i have a problem at hand which needs image to be converted into YCbCr color space before further processing. I have read about YCbCr and conversion process but the problem is i have no idea how i will store the YCbCr data in image format and which image format will support it.
i mean in bmp images rgb components are stored in bgr format, bytes should be multiples of 4 etc, but what about YCbCr? how they are represented?
i m sorry if this sounds very lame. I googled it a little but the thing is i don't think i m going in right direction. Actually this is for my final project and i m running out of time.
Update: actually there is no need to store it in some image container although tiff and jpeg can be used. i get around it by just converting rgb to YCbCr processing it and then converting it back to rgb pixel by pixel.
Both the formats only need three bytes for each pixel. So, as long as you store your pixels in some uncompressed format such as ppm, you do not need to bother about the conversion. When you are writing, put the Y into R, Cb int G and Cr into the blue bytes respectively. When you read in the values, it is up to to your program to interpret them - the default interpretation of most image processing programs is to treat them as RGB, but you can tell it to read them in as YCbCr
If you choose to store it in some compressed format such as jpeg, the values that you read back might not be the same as the ones that you store, but the decision depends on the accuracy that you need.
How can I convert a 24-bit colour System.Drawing.Bitmap to an indexed (256-colour) format? I'm having trouble working out how to calculate the palette. I can iterate over the pixels and use an int[] to contain the various colours but the problem comes when there are more than 256 colours. Is there a way to convert to an indexed format and extract a 256-colour palette from an Bitmap ?
Using the Bitmap Clone Method you can directly convert the Source Image to a 256 color Palette Indexed image like this:
Bitmap Result = Source.Clone(new Rectangle(0, 0, Source.Width, Source.Height), PixelFormat.Format8bppIndexed);
Then if you want access the Palette Colors, just use the Result.Palette.Entries property.
I had the same challenge earlier. It's possible to solve using GDI+ in .Net.
This article helped me a lot (including samples): http://msdn.microsoft.com/en-us/library/Aa479306
For best quality use "Octree-based Quantization".
WPF has access to the Windows Imaging Component, from there you can use a FormatConvertedBitmap to convert the image to a new pixel format. WIC is much much faster than the System.Drawing methods on Vista and 7 and will allow you a lot more options.
This is not built-in but you can either use external .NET libraries for this or shell out to the console to invoke ImageMagic.
Some reading material to get you started.
Graphic Gems I pp. 287-293, "A Simple Method for Color Quantization: Octree Quantization"
B. Kurz. Optimal Color Quantization for Color Displays. Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition, 1983, pp. 217-224.
Graphic Gems II pp. 116-125, "Efficient Inverse Color Map Computation"
This paper describes an efficient technique to map actual colors to a reduced color map, selected by some other technique described in the other papers.
Graphic Gems II pp. 126-133, "Efficient Statistical Computations for Optimal Color Quantization"
Xiaolin Wu. Color Quantization by Dynamic Programming and Principal Analysis. ACM Transactions on Graphics, Vol. 11, No. 4, October 1992, pp 348-372.
I need to convert a RGB (jpg) grayscale CMYK using only to black channel (K).
I'm trying to do this with imageglue, but the result is not what i'm looking for since it converts the grays using the C,M and Y channel and leaves the black channel to 0%.
What I need is if anyone has experience in using any other library/api in .net that could work?
I would start by looking at the ColorConvertedBitmap class in WPF. Here is a link to the docs and a basic example:
http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.colorconvertedbitmap(VS.85).aspx
Have you triedAForge.Net?
There is also ImageMagick, a c++ framework for image processing, with a .net wrapper (google for MagickNet)
Her is RGB to/from CMYK question which is related this one:
How is 1-bit bitmap data converted to 8bit (24bpp)?
I found The bitmap transform classes useful when trying to do some image format conversions but ... CYMK is one of the most complicated conversions you can tackle because there is more than one way to represent some colours. In particular equal CYM percentages give you shades of grey which are equivalent to the same percentage of K. Printers often use undercolour removal/transformation which normalises CYMK so that the a large common percentage is taken from CYM and transfered to the K. This is suppose to give purer blacks and grey tones. So even if you have a greyscale image represented using nothing but CYM with a zero black channel it could still print using nothing but K when you get it to a printer using undercolour removal.