There have any process to detect an image is a black&white image or a colored image? - swift2

I need to detect an image is a color image or black&white image. But don't understand what will be the process or there have any function to detect it. If there have no function to detect it then what will be the process?

Image file has mode, which tells if it is RGB, grayscale or B&W.
I assume you know that and you are trying to examine a RGB image to see if it only has black / white color. In this case you can calculate the histogram of the image in all R/G/B channels, the black and white will have two sharp peaks in all three channels.
Please use a image editing software like GIMP and experiment.

Related

Detecting anti-aliased or undersampled text image

I have an image that is essentially a text document (black and white) but due to anti-aliasing/undersampling applied during scanning, the image contains a lot of color, light tone pixels and is thus saved as a full-color image i.e: takes a lot of space.
My goal is to be able to detect Black and White image candidates in order to convert them from full color to B&W which dramatically reduces their size.
Is there a way to detect such anti-aliased/undersampled images? Doing color pixel analysis doesn't help because the colored pixels end up being close in amount to the black pixels... Essentially I want to be able to detect that the colored pixels come from anti-aliasing/undersampling a black & white image and not from a picture type image.
Here is an example image:
As you can see there are many more colors than just black. However this image is a good candidate for Black & White / Greyscale conversion instead of full color. How can I detect such images? Please note that in this example the colors tend to be on the grey side but there are many cases where they are cyan or brown etc.
I think it is a valid question. I don't have 50 reputation to post a comment so I will post this as an answer.
Basically, in a black and white anti-aliased image the various grey colors are opacity differences of the black color. If we observe those pixels they will be like these listed below. So, if the operation is a color manipulation then apply the same opacity picked up from those grey pixels to the new color.
rgba(0,0,0,0.6)
rgba(0,0,0,0.9)
rgba(0,0,0,0.5)
rgba(0,0,0,0.9)
rgba(0,0,0,0.6)
rgba(0,0,0,0.1)
rgba(0,0,0,0.5)
In my opinion, the pixels other than grey, in this example image, cyan and brown as it appears can be safely ignored because they seemed like not part of the original text. If there were a few more example images of non grey pixels would have been good. But if we cannot ignore them just need to get the pixel opacity and apply the same color manipulation. In other words we treat them as black pixels.

How to seprate RGB planes as three different gray scale images?

I want to seprate RGB planes of a color image as three gray scale image in MATLAB. But they are colored. How can I do it? I use the below code:
red = I(:,:,1); % Red channel
green = I(:,:,2); % Green channel
Using image will show the matrix as an image with the default colour map of whatever version of MATLAB you are using. For version R2014b and higher, it will show this in the parula colour map and other versions show this in the jet colour map. If you wish to visualize this as a grayscale image, you must use colormap gray; after you call image.
However, if you have the Image Processing Toolbox, you can simply use imshow and single channel images default to showing the contents as grayscale.

Issue with binarization of gray colored text of Tesseract

I am using Tesseract to recognize some values from the photo which is taken via camera of a phone. My problem is that I cannot recognize numbers which are written in gray color. I know that tesseract performs binarization on the input image. I manually performed the binarization and I realized that all gray texts disappear after binarization. As you can see in the binarized image, there are not any values appeared infront of sollwert and pos/neg toleranz. I can manually set a high threshold to keep my gray colored text,but I need a automatic way in my app. Beside that, the high threshold returns a mostly black image which it also lost some of information. Do you have any suggestions on how to keep my gray color text after binarization?
Thanks in advance

How can I binarize images with text? [MATLAB]

I have a problem with a binarization method.
I have images with text, which I want to binarize.
I want the text ends up being white, but there are images with the text darker than the background and there are images with text less dark than the background.
I want to binarize images like these, but I want the text in white color in the binarized images.
By the way, I am binarizing images with this code. This code is good for images with text darker than the background but it isn't good for text less darker than the background. I think I need a method to know if the text is more or less dark than the background for to invert or no invert the binarization.
umb = graythresh(originalImage);
binaryImage =(~im2bw(originalImage,umb));
How can I do it?
Thanks a lot for the help
there are 2 possible solutions which I had in mind:
solution1:
generate a grayscale image using rgb2gray function.
generate a histogram from the grayscale image, and ignore the transparent pixels. you can use imhist function.
check what is the histogram maximal value. if the value is high - the background is probably light and the text should be darker than the background. in this case - take the negative image (for example, by using imcomplement), and then binarize it. otherwise - you can binarize it as is.
solution 2:
the solution asserts that the image is simple enough, i.e. doesn't have a lot of connected components other than the letters.
binarize the input image.
divide the image into connected components using bwconncomp function.
for each connected component find it's representative value, it can either be 0 or 1
check what is the most common represantative value. if it is 1 - the letters are dark. in this case take the negative image and than binarize. otherwise - binarize the input image as is.
good luck!

How to Convert Gray scaled image to RGB image?

I am on MAC OSX.
How to convert an gray scaled image to the RGB format.
Can i use the CIFilters for converting? Or any other way
And also i want to reverse the operation. i.e., convert the RGB format to Gray scaled format.
Regards,
Dhanaraj.
You can draw the grayscale image into an RGB-color context and export that image. Of course, the ability to draw a grayscale image into a non-grayscale context means you probably don't need to convert the image in the first place, since it will be done for you on-the-fly.
Core Image requires RGB images as input and produces them as output. I think it will convert a non-RGB image for you, so you could just use some simple filter in its identity configuration, but that's unnecessary.
What are you really trying to do that requires you to convert the image?

Resources