how to clear the border of matrix?
Show older comments
I have a label image matrix
img=
1 1 1 2 2 2 3 3 3 3
1 2 2 2 9 3 3 3 3 3
1 1 9 9 9 9 9 9 3 3
1 8 8 8 8 8 8 8 8 3
1 8 8 8 7 7 7 7 7 3
1 7 7 7 7 1 1 7 7 3
1 1 1 1 1 1 1 1 1 1
I want to clear the side border and register it and clear the inside matrix with the value is same as side so turn them into 0.
side=
1 1 1 2 2 2 3 3 3 3
1 3
1 3
1 3
1 3
1 3
1 1 1 1 1 1 1 1 1 1
side =(1,2,3)
result=
0 0 0 0 0 0 0 0 0 0
0 0 0 0 9 0 0 0 0 0
0 0 9 9 9 9 9 9 0 0
0 8 8 8 8 8 8 8 8 0
0 8 8 8 7 7 7 7 7 0
0 7 7 7 7 0 0 7 7 0
0 0 0 0 0 0 0 0 0 0
Accepted Answer
More Answers (1)
Image Analyst
on 4 Dec 2015
If you want, you can just set the rows and columns to zero
img = [1 1 1 2 2 2 3 3 3 3
1 2 2 2 9 3 3 3 3 3
1 1 9 9 9 9 9 9 3 3
1 8 8 8 8 8 8 8 8 3
1 8 8 8 7 7 7 7 7 3
1 7 7 7 7 1 1 7 7 3
1 1 1 1 1 1 1 1 1 1];
result = img;
result(1,:)=0;
result(end,:)=0;
result(:,1)=0;
result(:,end)=0
4 Comments
Image Analyst
on 4 Dec 2015
By the way, this doesn't look like a labeled image because you don't have paths of zeros separating the blobs. And if it's a labeled image that came from a binary image and you didn't want to include blobs that touched the border (because the object is only partially there), you'd use imclearborder().
Rather, it looks exactly like a classified image where each pixel is assigned a class, like background, material 1, material 2, etc.
Tan Wen Kun
on 4 Dec 2015
Edited: Tan Wen Kun
on 4 Dec 2015
Image Analyst
on 4 Dec 2015
I don't understand any of what you said. But whatever . . . you've accepted Guillaume's answer so I guess your problem is resolved now and that's what counts. Good luck.
Tan Wen Kun
on 4 Dec 2015
Categories
Find more on Convert Image Type in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!