Filter löschen
Filter löschen

how to clear the border of matrix?

6 Ansichten (letzte 30 Tage)
Tan Wen Kun
Tan Wen Kun am 4 Dez. 2015
Kommentiert: Tan Wen Kun am 4 Dez. 2015
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

Akzeptierte Antwort

Guillaume
Guillaume am 4 Dez. 2015
Bearbeitet: Guillaume am 4 Dez. 2015
It's actually very simple using set operations:
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(ismember(result, union(result(:, [1 end]), result([1 end], :)))) = 0
union gives you the unique labels that are part of the vertical and horizontal borders. ismember tells you which labels at what position are parts of that union. You then use the logical vector generated by ismember to set the respective labels to 0.

Weitere Antworten (1)

Image Analyst
Image Analyst am 4 Dez. 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 Kommentare
Image Analyst
Image Analyst am 4 Dez. 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
Tan Wen Kun am 4 Dez. 2015
Because I doing some dumb image segmentation so sometime my question is look abit foolish~my lecturer just give me the step that whatever now me can do in time so my work is abnormal than normal image segmentation

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Image Processing Toolbox finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by