Hello all, below is a binary image
i want to remove the border pixels as shown in red (i used paint to highlight ) in the below image
I cannot use imclearborder for this task as it eliminates any pixel attactched to the border too. So i was thinking we could write a loop and set the first and last white oixel in each row to zero. I am not quite sure how to write the loop. Can anyone help me with this problem?

댓글 수: 9

KALYAN ACHARJYA
KALYAN ACHARJYA 2020년 5월 13일
편집: KALYAN ACHARJYA 2020년 5월 13일
No need of "for loop" here, may be multiple logic required. As the expected ROI is not clearly distinguishable from other regions in the image (in shapes or sizes)
Apply the morphological operation, it may help. Please sure it is possible to accomplished.
Rik
Rik 2020년 5월 13일
You could maybe start with imclose.
Apoorva Maiya
Apoorva Maiya 2020년 5월 13일
I want to remove the portion shown in red I'm not sure how closing would help, thanks for the advice.
Rik
Rik 2020년 5월 13일
Ah, sorry I misspoke. You can use imopen to separate the outer line from the other structures. One of the problems is that your outer line is not a single pixel wide, so simply removing the rightmost and leftmost white pixels will not help.
Apoorva Maiya
Apoorva Maiya 2020년 5월 14일
oh, I hadn't observed that thanks for the tip. So now, If i manage to get a one pixel wide image somehow through morphological operations, then how do i go about removing the rightmost and leftmost pixels from each row?
Walter Roberson
Walter Roberson 2020년 5월 14일
I wonder if skeletonization would help for your purpose?
Also see imtophat and imbottomhat
Apoorva Maiya
Apoorva Maiya 2020년 5월 14일
yes, skeletonization helped to reduce the outlines to one pixel width. Thank you for the advice. Now, how do I remove the extreme pixels in the image? can you guide me with this please?
hey, below is the same image after skeletonization
I have managed to get the rightmost and leftmost white pixel in each row with the following code:
B = bwskel(img);
[rows,col]=size(B);
rightEdgeColumn = zeros(1,rows);
leftEdgeColumn=zeros(1,rows);
for row=1:rows
col1 = find(B(row, :), 1, 'last');
col2 = find(B(row, :), 1, 'first');
if ~isempty(col1) && ~isempty(col2)
rightEdgeColumn(row) = col1;
leftEdgeColumn(row) = col2;
end
end
Can anybody help me set those pixels to zero? I want the pixels in rightEdgeColumn and LeftEdgeColumn to be zero. Thank you in advance.
Apoorva Maiya
Apoorva Maiya 2020년 5월 17일
thank you all for your response, i was able to write the code myself.

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

 채택된 답변

Apoorva Maiya
Apoorva Maiya 2020년 5월 17일

0 개 추천

B = bwskel(img); %skeletonized image
[rows,col]=size(B);
%% finding right edge and left edge
rightEdgeColumn = zeros(1,rows);
leftEdgeColumn=zeros(1,rows);
for row=1:rows
col1 = find(B(row, :), 1, 'last');
col2 = find(B(row, :), 1, 'first');
if ~isempty(col1) && ~isempty(col2)
rightEdgeColumn(row) = col1;
leftEdgeColumn(row) = col2;
end
end
%%removing the edge pixels
for i=1:length(rightEdgeColumn)
k=rightEdgeColumn(i);
if k==0 %% if the whole row has no white pixels
B(i,:)=0;
else
B(i,k)=0;
end
end

추가 답변 (0개)

질문:

2020년 5월 13일

답변:

2020년 5월 17일

Community Treasure Hunt

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

Start Hunting!

Translated by