How to fill edges only in Blob area

1 回表示 (過去 30 日間)
Hash ir
Hash ir 2017 年 2 月 19 日
回答済み: Image Analyst 2017 年 2 月 22 日
I am able to draw a blob inside an image and then i want to extend the blob until it hit's black line or edge,simple suggestions on how to do it?
for example i had a circle edge here black i want to extend red blob if hit to an edge then stop extending.note only fill those areas where i place these blob.

回答 (2 件)

Image Analyst
Image Analyst 2017 年 2 月 19 日
What is that? It looks like a tomato worm or something. You can use imfill() to fill binary blobs. You don't have a binary image yet. And even if you did, there would be lots of regions that would fill and you'd end up with a pretty solid image. I think you need to do a better job on your initial segmentation.
  5 件のコメント
Image Analyst
Image Analyst 2017 年 2 月 21 日
Sorry, I don't believe that if you applied imfill() to the top image, it would produce the bottom image. imfill() works on binary images. How did you get your Sobel image: from edge() or imgradient()?
Hash ir
Hash ir 2017 年 2 月 21 日
編集済み: Hash ir 2017 年 2 月 21 日
thanks for the help.I think i cannot explain clear enough or there is some other issue.I changed the post i hope you can help me on what i wanted.

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


Image Analyst
Image Analyst 2017 年 2 月 22 日
Regarding your total change of image, see this code:
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 15;
%===============================================================================
% Get the name of the image the user wants to use.
baseFileName = 'red_spot.png';
% Get the full filename, with path prepended.
folder = pwd
fullFileName = fullfile(folder, baseFileName);
%===============================================================================
% Read in a demo image.
rgbImage = imread(fullFileName);
% Get the dimensions of the image. numberOfColorChannels should be = 3.
[rows, columns, numberOfColorChannels] = size(rgbImage);
% Display the original color image.
subplot(2, 2, 1);
imshow(rgbImage, []);
axis on;
caption = sprintf('Original RGB Color Image, %s', baseFileName);
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');
% Set up figure properties:
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
% Get rid of tool bar and pulldown menus that are along top of figure.
set(gcf, 'Toolbar', 'none', 'Menu', 'none');
% Give a name to the title bar.
set(gcf, 'Name', 'Demo by ImageAnalyst', 'NumberTitle', 'Off')
drawnow;
hp = impixelinfo(); % Set up status line to see RGB values when you mouse over the image.
% Extract the individual red, green, and blue color channels.
redChannel = rgbImage(:, :, 1);
greenChannel = rgbImage(:, :, 2);
blueChannel = rgbImage(:, :, 3);
% Get a mask for the white pixels.
mask = redChannel == 255 & greenChannel == 255 & blueChannel == 255;
% Display the image.
subplot(2, 2, 2);
imshow(mask, []);
axis on;
caption = sprintf('Mask Image');
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');
drawnow;
% Get rid of portion hitting the edges of the image.
mask = imclearborder(mask);
% Display the image.
subplot(2, 2, 3);
imshow(mask, []);
axis on;
caption = sprintf('Final Mask Image');
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');
drawnow;
% Find the middle of the image
midRow = round(rows/2);
midCol = round(columns/2);
% Find the color of the red spot in the middle
r = redChannel(midRow, midCol);
g = greenChannel(midRow, midCol);
b = blueChannel(midRow, midCol);
% Make the mask pixels the same reddish color as in the original image.
redChannel(mask) = r;
greenChannel(mask) = g;
blueChannel(mask) = b;
% Recombine separate color channels into a single, true color RGB image.
rgbImage = cat(3, redChannel, greenChannel, blueChannel);
% Display the image.
subplot(2, 2, 4);
imshow(rgbImage, []);
axis on;
caption = sprintf('Final RGB Image');
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');
drawnow;

カテゴリ

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