How to get the ROI boudary value Correctly ?
1 回表示 (過去 30 日間)
古いコメントを表示
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 件のコメント
採用された回答
Image Analyst
2017 年 4 月 1 日
編集済み: Image Analyst
2017 年 4 月 1 日
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 件のコメント
Image Analyst
2017 年 4 月 2 日
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)
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!