How can i detect silver pixels in an image?

I'm trying to detect all the pixels with silver colors in my image. I tried to convert the image from RGB to HSV but I saw that every silver pixel is very different from another and therefore we couldn't identify all the silver pixels. I'm trying to understand if it's possible to use HSV to solve this problem or maybe there is a better way to detect all the silver pixels?

I'm trying to use this code that will mark all the silver pixels in blue:

I chose the Hue,Saturation and Value (HSV) according to wikipedia to identify the silver color, therefore Hue doesn't matter, Saturation is 0-0.1 and Value is 0.65-0.85.

clear all; close all; clc; imtool close all;

im = imread('image.jpg');

size_x = size(im,1);
size_y = size(im,2);
size_z = size(im,3);

hsv = rgb2hsv(im);

for i = 1:size_x
    for j = 1:size_y
        if (hsv(i,j,2) < 0.1) && (hsv(i,j,3) > 0.65) && (hsv(i,j,3) < 0.85)  
            im(i,j,1) = 0;
            im(i,j,2) = 0;
            im(i,j,3) = 255;


with this Image:

Thanks in advance.

1 answer

  • answered 2018-03-11 22:35 Cris Luengo

    The difference between a white pixel and a grey pixel is the amount of light that falls on it. You can see this in your picture, the whitish background changes brightness from left to right, going from middle grey to light grey. We perceive it all as white.

    The same is true for silver. Silver is a white/grey color, but we perceive it differently because it has specular reflections. This is what characterizes metal surfaces. But the color of the pixels themselves are just grey and white.

    That is to say, you cannot use color segmentation to distinguish silver contacts from white paper.

    I would suggest you look for the shapes of interest, rather than the colors of interest.