Extracting blue objects of interest

5 次查看(过去 30 天)
Izuru
Izuru 2015-3-24
Hi,
I have an image of a circuit board with very blue chips. I want to display the blue chips as blue and display the rest of the board in greyscale.
My approach so far is:
image = imread('board.tif');
redBand = image(:,:,1); greenBand = image(:,:,2); blueBand = image(:,:,3);
After this I want to get everything in greyscale but display the blue chips on the same image. I think I have to put a red and green mask but I'm unsure how to do this. Any insights?

回答(2 个)

Christiaan
Christiaan 2015-3-24
Dear Izuru,
I made a code for you, where first the color 'blue' is detected at a certain threshold. (here 200) Then with a for loop, all points where the color is below the threshold are neglected. The image I used has been put in the attachment.
clc; clear all; close all;
% Read standard MATLAB demo image.
rgbImage = imread('board.jpg');
% Display the original image.
subplot(1, 3, 1);
imshow(rgbImage);
title('Original RGB Image');
% Maximize figure.
set(gcf, 'Position', get(0, 'ScreenSize'));
% Split into color bands.
redBand = rgbImage(:,:, 1);
greenBand = rgbImage(:,:, 2);
blueBand = rgbImage(:,:, 3);
% Display them.
subplot(1, 3, 2);
imshow(blueBand);
title('Blue Band');
% here objects which are parly blue make totaly blue
for i=1:152
for j=1:229
if blueBand(i,j)>200
redBand(i,j)=0.1;
greenBand(i,j)=0.1;
blueBand(i,j)=200;
end
end
end
% here objects which are not blue to dark
for i=1:152
for j=1:229
if blueBand(i,j)<200
redBand(i,j)=redBand(i,j)*0.2;
greenBand(i,j)=greenBand(i,j)*0.2;
blueBand(i,j)=blueBand(i,j)*0.2;
end
end
end
% Display them.
subplot(1, 3, 3);
im = cat(3,redBand,greenBand,blueBand);
imshow(im);
title('Blue Objects');
A second possibility would be using a tool from the File Exchange. A nice feature is 'imoverlay'. If you call this tool by writing in the prompt : >>imoverlay_tool and then use as a background 'blueband' (0-255), in the foreground'blueband' (200-250) and in the overlay (alpha 0.8) you obtain a figure that is blue where the objects are blue and the rest is gray.
Good luck! Christiaan

Image Analyst
Image Analyst 2015-3-24
You can use my demos that find specified colors. Try the delta E one, or the one that does it in HSV color space.
Change the thresholds in the HSV one to get blue instead of yellow. For the delta E demo, you don't need to do that because you give it an example of the color you want to find by tracing a small region.

类别

Help CenterFile Exchange 中查找有关 Computer Vision with Simulink 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by