# how to change the interior pixel of a closed boundary surface to a different pixel using MATLAB?

조회 수: 2(최근 30일)
M.S. Khan 2021년 2월 4일
댓글: M.S. Khan 2021년 2월 7일
I have a closed boundary surface of an object. i want to fill the interior which is already zero. How can i change the zero to any other digit so that i can do some mathematical operations. Regards for all cooperation of community members.
i have used the following code to handle it but i couldnt figure out.
Perimeter=bwperim(A)
interior_filled = imfill(A,'holes')
A = 3*double(A)
interior_filled = 2*double(interior_filled)
interior_filled(Perimeter)=A(Perimeter)
The above code is giving me the closed boundary surface? Could anyone guide me how to replace the interior that is already filled as zero but i want to repalce with another number number like 2.
Thanks for all guidance in advance.
##### 댓글 수: 1표시숨기기 없음
Image Analyst 2021년 2월 7일
The shape is not closed. See the apex at the left. Do you want to close it, like with bwconvhull()? 댓글을 달려면 로그인하십시오.

### 채택된 답변

Image Analyst 2021년 2월 7일
The shape is not closed but you can close it with bwconvhull() if you're okay with the shape being a convex shape, like your rectangle.
A = logical(A);
subplot(2, 1, 1);
imshow(A);
interior_filled = bwconvhull(A);
subplot(2, 1, 2);
imshow(interior_filled); ##### 댓글 수: 1표시숨기기 없음
M.S. Khan 2021년 2월 7일
Thanks Dear Image Analyst. As usual, you are always very helpful. Regards

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

### 추가 답변(4개)

KSSV 2021년 2월 4일
Yopu can exclude the boundaries by indexing right?
A = interior_filled(2:end-2,2:end-2) ;
Now you apply the given values as you have tried on A.
##### 댓글 수: 1표시숨기기 없음
M.S. Khan 2021년 2월 5일
hi dear KSSV, thanks for your guidance. it doesnt work because arrays size will change and will give error.

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

Walter Roberson 2021년 2월 5일
fill the holes. subtract the original, and what is left will be the interiors. Multiply by constant and add to the original.
##### 댓글 수: 1표시숨기기 없음
M.S. Khan 2021년 2월 5일
Thanks Walter for reply. i have zeros inside and outside the boundary surface. so multipling zero and constant will again be zero. i need to deal only the interior of the boundary.

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

yanqi liu 2021년 2월 5일
clear all; clc; close all;
b = im2bw(A);
b = imclose(b, strel('disk', 3));
b2 = imfill(b, 'holes');
b3 = logical(b2 - b);
A2 = im2uint8(mat2gray(A));
A2(b3) = 128;
figure;
imshowpair(A,A2,'montage'); please use different value, such as 64，100，128，……
##### 댓글 수: 1표시숨기기 없음
M.S. Khan 2021년 2월 5일
Hi Dear Yani Lie, thanks for your guidance. if you see the top in image or A2, still there are some zeros which are not replaced with 128. Can we figure it out. Regards

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

yanqi liu 2021년 2월 5일
sir，may be use the follow code
clear all; clc; close all;
b = im2bw(A);
b = imclose(b, strel('line', 3, -45));
b2 = imfill(b, 'holes');
b3 = logical(b2 - b);
A2 = im2uint8(mat2gray(A));
A2(b) = 0;
A2(b3) = 128;
figure;
imshowpair(A,A2,'montage'); ##### 댓글 수: 2표시숨기기 이전 댓글 수: 1
yanqi liu 2021년 2월 7일
the reason is
at the sharp corner on the left, there is a gap that needs to be filled. may be can zoom in to check

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

### 범주

Find more on Matrix Indexing in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!