WolframAlpha.com
WolframCloud.com
All Sites & Public Resources...
Products & Services
Wolfram|One
Mathematica
Wolfram|Alpha Notebook Edition
Finance Platform
System Modeler
Wolfram Player
Wolfram Engine
WolframScript
Enterprise Private Cloud
Application Server
Enterprise Mathematica
Wolfram|Alpha Appliance
Enterprise Solutions
Corporate Consulting
Technical Consulting
Wolfram|Alpha Business Solutions
Resource System
Data Repository
Neural Net Repository
Function Repository
Wolfram|Alpha
Wolfram|Alpha Pro
Problem Generator
API
Data Drop
Products for Education
Mobile Apps
Wolfram Player
Wolfram Cloud App
Wolfram|Alpha for Mobile
Wolfram|Alpha-Powered Apps
Services
Paid Project Support
Wolfram U
Summer Programs
All Products & Services »
Technologies
Wolfram Language
Revolutionary knowledge-based programming language.
Wolfram Cloud
Central infrastructure for Wolfram's cloud products & services.
Wolfram Science
Technology-enabling science of the computational universe.
Wolfram Notebooks
The preeminent environment for any technical workflows.
Wolfram Engine
Software engine implementing the Wolfram Language.
Wolfram Natural Language Understanding System
Knowledge-based broadly deployed natural language.
Wolfram Data Framework
Semantic framework for real-world data.
Wolfram Universal Deployment System
Instant deployment across cloud, desktop, mobile, and more.
Wolfram Knowledgebase
Curated computable knowledge powering Wolfram|Alpha.
All Technologies »
Solutions
Engineering, R&D
Aerospace & Defense
Chemical Engineering
Control Systems
Electrical Engineering
Image Processing
Industrial Engineering
Mechanical Engineering
Operations Research
More...
Finance, Statistics & Business Analysis
Actuarial Sciences
Bioinformatics
Data Science
Econometrics
Financial Risk Management
Statistics
More...
Education
All Solutions for Education
Tech & Trends
Machine Learning
Multiparadigm Data Science
High-Performance Computing
Quantum Computation Framework
Software & Web
Software Development
Authoring & Publishing
Interface Development
Web Development
Sciences
Astronomy
Biology
Chemistry
More...
All Solutions »
Learning & Support
Learning
Wolfram Language Documentation
Fast Introduction for Programmers
Wolfram U
Videos & Screencasts
Wolfram Language Introductory Book
Webinars & Training
Summer Programs
Books
Need Help?
Support FAQ
Wolfram Community
Contact Support
Premium Support
Paid Project Support
Technical Consulting
All Learning & Support »
Company
About
Company Background
Wolfram Blog
Events
Contact Us
Work with Us
Careers at Wolfram
Internships
Other Wolfram Language Jobs
Initiatives
Wolfram Foundation
MathWorld
Computer-Based Math
A New Kind of Science
Wolfram Technology for Hackathons
Student Ambassador Program
Wolfram for Startups
Demonstrations Project
Wolfram Innovator Awards
Wolfram + Raspberry Pi
Summer Programs
More...
All Company »
Search
Legacy Documentation
Digital Image Processing
(2000)
This is documentation for an obsolete product.
Current products and services
User's Guide
Image Segmentation
7.6 Example: Color Image Segmentation
In this example we use clustering to segment an example image according to color features. Subsequently we show examples of color-selective masking operations. This is accomplished by clustering the pixel values in the 3D RGB color space. The determination of the number of clusters comes from a visual examination of the example image. Iterative refinement of the clustering outcome is possible based on a global classification measure. Alternatively, the classification result may be refined in a postprocessing step, by removing outliers from each of the clusters and appropriately labeling them as belonging to none of the selected color classes.
In[1]:=
This reads the
beans
image and extracts a subregion for further processing.
In[2]:=
Here we cluster the color pixel values into three groupings according to their RGB values. The clusters define background, green bean, and red bean pixels. The initial seed values are estimates of typical color values in these three regions.
In[3]:=
Here we verify the resulting clustering by listing the cluster centers.
In[4]:=
Out[4]=
This shows the number of pixels in each of the color clusters.
In[5]:=
Out[5]=
This shows a scatter diagram of the cluster assignment of all the image pixels.
In[6]:=
Out[6]=
Given these classification results, we can now proceed with selective image operations. Here we find the positions of all the red pixels in the example image.
In[7]:=
Here we flood the region occupied by red beans with a uniform red color.
In[8]:=
This shows the result.
In[9]:=
Out[9]=
Here we mask all the nonred pixels, which includes the background and green bean pixels, with a uniform gray value. First we find the positions of all the pixels that belong to this category.
In[10]:=
This replaces all affected pixels with a uniform gray value.
In[11]:=
This shows the result.
In[12]:=
Out[12]=
Enable JavaScript to interact with content and submit forms on Wolfram websites.
Learn how »