필터 지우기
필터 지우기

how to apply the result of bwboundaries() output ?

조회 수: 2 (최근 30일)
Piyum Rangana
Piyum Rangana 2017년 4월 2일
댓글: Piyum Rangana 2017년 4월 4일
This is the code.
%%%%%%Code begins %%%%
boundaries = bwboundaries(img);
NumOfBoundaries = size(boundaries, 1);
[x y t]= size(rgbImage);
ZeroPlate = redChannel == 0;
for k = 1 : NumOfBoundaries
thisBoundary = boundaries{k};
%%%%%I want to set Value '1' to 'ZeroPlate' co-%%%ordination given in 'thisBoundary' %%%%%%%%
%%%%%---------------the code goes here------------------%%%%
%%%%%end %%%%%
end
I want to set value '1' to the ZeroPlate (which is red-channel of the given image in which the pixel values are all zeros) according to the co-ordination obtaining from the values of 'boundaries' variable. How to do this ?

채택된 답변

Image Analyst
Image Analyst 2017년 4월 3일
Try this:
%%%%%%Code begins %%%%
boundaries = bwboundaries(img);
NumOfBoundaries = size(boundaries, 1);
% Get size.
% Note: it is NOT NOT NOT [x,y,numColors] = size(rgbImage) as you had it.
% rows is y, NOT x. But actually this line is not needed.
[rows, columns, numberOfColorChannels]= size(rgbImage);
ZeroPlate = redChannel == 0;
for k = 1 : NumOfBoundaries
thisBoundary = boundaries{k};
% Set Value '1' to 'ZeroPlate'
% coordinates given in 'thisBoundary'
x = thisBoundary(:, 1);
y = thisBoundary(:, 2);
for index = 1 : length(x)
% Get row and column.
row = y(index);
column = x(index);
% Set that row and column = true = 1.
ZeroPlate(row, column) = true;
end
end
  댓글 수: 3
Image Analyst
Image Analyst 2017년 4월 4일
I set it equal to true because ZeroPlate is a binary image and you said you want the value to be 1 (true).
Actually you're right sort of - I switched x and y. I thought bwboundaries returned (x,y) coordinates but it doesn't - it returns (row, column) which is (y, x). So the correct code should be:
for k = 1 : NumOfBoundaries
thisBoundary = boundaries{k};
% Set Value '1' to 'ZeroPlate'
% coordinates given in 'thisBoundary'
x = thisBoundary(:, 2);
y = thisBoundary(:, 1);
for index = 1 : length(x)
% Get row and column.
row = y(index);
column = x(index);
% Set that row and column = true = 1.
ZeroPlate(row, column) = true;
end
end
Piyum Rangana
Piyum Rangana 2017년 4월 4일
Thanks a lot for the support.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by