Determine if image is Grayscale or Color using JavaScript?

Take a look at pixastic.com/lib/docs/actions/colorhisto... This will easily provide the data you need to determine this.

Perfect! I found that if the image is grayscale, the RGB values returned are the same. For example, a grayscale image will return something like (9445,534,501,508,442,448...) for the rvals, (9445,534,501,508,442,448...) for the gvals and (9445,534,501,508,442,448...) for the bvals.

On the other hand, a color image will return (1,3,5,3,8...), (1,2,3,0,3...) and (1,2,3,0,3...) respectively. Thanks a TON for your help! – devnull Dec 1 at 15:11 Here is the cheap solution using that library: (I give up on trying to format.

I'm a frickin noob. Shoot me. Someone will fix this.

Sorry for my ignorance. ) function isGrayscale(img) { var histret = {}; Pixastic. Process(document.

GetElementById(img), "colorhistogram", {paint:true, returnValue:histret}); return ((histret.rvals.toString() == histret.gvals.toString()) && (histret.gvals.toString() == histret.bvals.toString())); } – devnull Dec 1 at 15:40.

Draw image to canvas loop through image data test for each pixel if red-cahnnel == green-channel == blue-channel (all color-channels have the same value) if true for all pixels it is grayscale, if you hit the first pixel that does not meat the condition you can stop and it is color.

If you have HTML5 ... – Alnitak Nov 30 at 16:58 @Alnitak caniuse. Com/canvas – Gerben Nov 30 at 17:00 yeah, right only in HTML5 (or browsers supporting the canvas object), but would it make sens to know if an image is grayscale if you cant do anything with the image then? If you only want to display a meta-information of the used colorspace on a website you could use some server-side program like imagemagick or some java stuff to determine the colorspace.

– zuloo Dec 1 at 10:25.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions