How to get the ROI boudary value Correctly ?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Piyum Rangana
el 1 de Abr. de 2017
Editada: Piyum Rangana
el 10 de Mayo de 2017
The code I am using mention below. From this code I tried to find the degraded area (damaged area). But the outcome of the code execution is like this. It seems like the output boundary values are not the real boundary values(Came them like rectangle). Could you please explain how to avoid that and the how to get the real boundary values of the inserted image ???
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/162491/image.jpeg)
0 comentarios
Respuesta aceptada
Image Analyst
el 1 de Abr. de 2017
Editada: Image Analyst
el 1 de Abr. de 2017
I already answered this in https://www.mathworks.com/matlabcentral/answers/331984-remove-the-unwanted-region-from-an-image#comment_440374
You're taking the wrong approach here. You don't want to call im2bw(), and you don't want to call bwtraceboundary(). You need to do color segmentation to find the white, as I showed you in your prior question. Then do regionfill() with the white mask.
4 comentarios
Image Analyst
el 2 de Abr. de 2017
OK, here's a full demo. At the end you have the x,y coordinates of the white holes from which you can do your custom inpainting algorithm.
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 = 'kandian.png';
% Get the full filename, with path prepended.
folder = pwd
fullFileName = fullfile(folder, baseFileName);
% Check if file exists.
if ~exist(fullFileName, 'file')
% The file doesn't exist -- didn't find it there in that folder.
% Check the entire search path (other folders) for the file by stripping off the folder.
fullFileNameOnSearchPath = baseFileName; % No path this time.
if ~exist(fullFileNameOnSearchPath, 'file')
% Still didn't find it. Alert user.
errorMessage = sprintf('Error: %s does not exist in the search path folders.', fullFileName);
uiwait(warndlg(errorMessage));
return;
end
end
%===============================================================================
% Read in demo image.
rgbImage = imread(fullFileName);
% Get the dimensions of the image.
[imageRows, imageColumns, numberOfColorChannels] = size(rgbImage);
% Display the original image.
subplot(2, 2, 1);
imshow(rgbImage, []);
axis on;
caption = sprintf('Original 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 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 of "white" where red, green, and blue are all high at the same location.
whiteMask = redChannel > 206 & greenChannel > 153 & blueChannel > 114;
% Display the image.
subplot(2, 2, 2);
imshow(whiteMask);
grid on;
axis on;
title('White Mask Image', 'FontSize', fontSize);
% bwboundaries() returns a cell array, where each cell contains the row/column coordinates for an object in the image.
% Plot the borders of all the coins on the original grayscale image using the coordinates returned by bwboundaries.
subplot(2, 2, 3);
imshow(rgbImage);
title('Outlines, from bwboundaries()', 'FontSize', fontSize);
axis image; % Make sure image is not artificially stretched because of screen's aspect ratio.
hold on;
boundaries = bwboundaries(whiteMask);
numberOfBoundaries = size(boundaries, 1);
for k = 1 : numberOfBoundaries
thisBoundary = boundaries{k};
plot(thisBoundary(:,2), thisBoundary(:,1), 'g', 'LineWidth', 2);
end
hold off;
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/183929/image.png)
Más respuestas (0)
Ver también
Categorías
Más información sobre Computer Vision with Simulink en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!