Detecting Background Color

Hi Everyone,
First I have no extensive knowledge about image processing but I want to apply a process which will detect the background color of some item photos. Basically, I want to know if the item’s background is white or not.

Currently I apply masking to my images but I don’t know what should I do next, after the masking I want to learn dominant color out of the masking.

Can you please guide me, I am willing to learn more.



Hi @caceter,
The tutorial Workflow you linked creates a binary image, you can use the Connected Component Analysis node to create a labeling from that. A labeling is like a mask image that you can use for different operations, one of which is regionally restricted calculation of image measurements (features). Using the Image Segment Features node you can extract measurements for each region in the labeling, e.g. the mean pixel value per color channel. This would give you an approximation of the mean color in that region. If you can provide us with a sample picture from you data, I can help you further.


Hi Gabriel,

Many thanks for your message, I am adding the sample images and their masked versions below you can take a look.

1 jpgafter%20mask 2 jpgafter%20mask 3 jpgafter%20mask 4 jpgafter%20mask 5 jpgafter%20mask

Hi @caceter,
I am sorry for the delayed reply, but I was finally able to take a look at these images.
I created a simple workflow that applies the mask to the image and then extracts the median pixel value of the background in each channel.
background-color.knwf (474.7 KB)

I’d like to look at your solution but got an error on Gaussian Convolution:
ERROR Gaussian Convolution 2:11 Error in row image1-mask.jpeg: No externalizer available with id ImageMetadataExt3
ERROR Gaussian Convolution 2:11 Execute failed: java.lang.RuntimeException: No externalizer available with id ImageMetadataExt3

Something is missing on my installation?

Oh sorry this workflow was created using a nightly version of KNIME Image Processing, you can just reset the Image reader nodes, and read the following two images:


Thank you. Will try.

Hi Gabriel,
Many thanks again, I don’t know how much time you spent on the workflow but huge respect :slight_smile:
I didn’t understand one thing, Splitter Node splits image according to which rules ? Because output is for one image sometimes coming like this:


Which part is presenting the background? Or should I take mean of groups?


Just a few minutes, I have been working on and with Image Processing in KNIME for years :smiley:.

The Splitter node splits the images as described in the node description:

Dimension selection
Select those dimensions here, which should stay together. I.e. for each selected subset, the non-selected dimensions will be split completely.

In this case this should mean the images are split into their color channels.

This looks like the joining of the different rows did not succeed correctly. The output of the metanode should look like the following for a single picture:


Hi Gabriel,

I’ve added 7 images and their masks, but output is coming like this. For which step I need to correct the joining.

I guess everything is ok before Node 36

Take a look into the Metanode (just double click it). There you can investigate the contained join nodes to find out where it goes wrong.

I guess Joiner node is fine in the metanode but Feature Calculator’s are giving more than 1 results for each image. Pls take a look at the SS


Ok this means that the Connected Component Analysis node finds more than one segment in your image,
you can either try filtering out these extra segments (if they are small) using the Segment Filter node, or improve the pre-processing of the masks, e.g. by increasing the sigma of the Gauss filter.