Azzera filtri
Azzera filtri

How to get the ROI boudary value Correctly ?

1 visualizzazione (ultimi 30 giorni)
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 ???

Risposta accettata

Image Analyst
Image Analyst il 1 Apr 2017
Modificato: Image Analyst il 1 Apr 2017
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 Commenti
Piyum Rangana
Piyum Rangana il 2 Apr 2017
Still I cannot understand how to get that boundary pixel values as u mentioned above ?
im=imread('img.png');
imshow(im)
redChannel = im(:, :, 1);
greenChannel = im(:, :, 2);
blueChannel = im(:, :, 3);
mask = redChannel > 206 & greenChannel > 153 & blueChannel > 114;
imshow(double(mask))
QQ = mask.*double(redChannel);
Image Analyst
Image Analyst il 2 Apr 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;

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by