Selecting dark areas of an image

10 ビュー (過去 30 日間)
justin kain
justin kain 2018 年 11 月 14 日
コメント済み: Image Analyst 2018 年 12 月 13 日
I have a question on how to upload an image, and then get matlab to select areas of the image that are darker in color. The image has a colors from yellow to black. I would like to get the program to select the black areas, and draw an elipse around it.
  4 件のコメント
justin kain
justin kain 2018 年 11 月 15 日
ImageLog.jpg
This is not the image, but a similar image to this one, Selecting dark regions like the one in the middle towards the bottom.
Image Analyst
Image Analyst 2018 年 12 月 13 日
Not exactly sure which region you're referring to. Can you attach another image where you've outlined the region of interest in red?

サインインしてコメントする。

回答 (1 件)

Mark Sherstan
Mark Sherstan 2018 年 12 月 12 日
編集済み: Mark Sherstan 2018 年 12 月 12 日
Try the following. I just put it together quickly (results on the bottom). You will need to adjust the tolerances of channel 3 to meet the requirments of your data. From there you can use bwareafilt, regionprops and insertObjectAnnotation to draw your circles. I draw a circle around the largest blob (according to the random channel 3 - value settings).
I = imread('image.png');
[BW,maskedRGBImage] = createMask(I);
BW2 = bwareafilt(BW,1);
stats = regionprops(BW2,'Centroid');
RGB = insertObjectAnnotation(I,'circle',[stats.Centroid 20],'','Color','cyan');
imshow(RGB)
function [BW,maskedRGBImage] = createMask(RGB)
%createMask Threshold RGB image using auto-generated code from colorThresholder app.
% [BW,MASKEDRGBIMAGE] = createMask(RGB) thresholds image RGB using
% auto-generated code from the colorThresholder app. The colorspace and
% range for each channel of the colorspace were set within the app. The
% segmentation mask is returned in BW, and a composite of the mask and
% original RGB images is returned in maskedRGBImage.
% Auto-generated by colorThresholder app on 12-Dec-2018
%------------------------------------------------------
% Convert RGB image to chosen color space
I = rgb2hsv(RGB);
% Define thresholds for channel 1 based on histogram settings
channel1Min = 0.000;
channel1Max = 1.000;
% Define thresholds for channel 2 based on histogram settings
channel2Min = 0.000;
channel2Max = 1.000;
% Define thresholds for channel 3 based on histogram settings
channel3Min = 0.000;
channel3Max = 0.275;
% Create mask based on chosen histogram thresholds
sliderBW = (I(:,:,1) >= channel1Min ) & (I(:,:,1) <= channel1Max) & ...
(I(:,:,2) >= channel2Min ) & (I(:,:,2) <= channel2Max) & ...
(I(:,:,3) >= channel3Min ) & (I(:,:,3) <= channel3Max);
BW = sliderBW;
% Initialize output masked image based on input image.
maskedRGBImage = RGB;
% Set background pixels where BW is false to zero.
maskedRGBImage(repmat(~BW,[1 1 3])) = 0;
end

カテゴリ

Help Center および File ExchangeImage Processing Toolbox についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by