How to make a rectangular shape with inner boundary having the value of 1 and outer boundary a value of 0?

Hi,
I am trying to make a rectangular shape with inner boundary value set as one and outer boundary value set as zero. Ideally a smoother transition from inner boundary to put boundary would be really helpful for my case. Following figure can explain the problem better:
In my implementation, I am struggling with the corners in particular with a linear transition from inner to outer boundary.
Following line should run the function to reproduce the the results of figure 2:
jQvals(Trow,Tcol,ouc,our,inc,inr,ptAbvCrk,ptBlwCrk,gridElems);
Relevant variable are in the attached mat file.
Looking forward to the feedback.

3 Comments

I am trying to make a rectangular shape with inner boundary value set as zero and outer boundary value set as one
In your figure illustrations, it's the other way around (inner boundary=1)

Sign in to comment.

 Accepted Answer

For example,
A=zeros(100);
A(30:70,30:70)=1;
A=max(0, 1-bwdist(A)/10);
A( abs( conv2(A,ones(3)/9,'same')-1)<=1e-6)=0;
imshow(A)

6 Comments

Thank you for the answer. I am doing the same for the region (finalMask) in the attached mat file. But it is not working. Can you guide about that case in particular? In this particular shape, the inner boundary will be one and the external boundary will be 0.
I recommend that you just start with the inner rectangle, like in my example. Don't bother drawing a thicker wall of 1's around it if you're only going to undo that later.
Actually I do need the external total region in the mask for my FEM implementation. Without making sure that the conditions of one at the inner boundary and 0 at the outer boundary, the problem cannot be solved for my case. That is why I am after this. I have spent couple of weeks in this already but could not come up with a solution.
Yes, but you want it to taper to zero not drop discontinuously. My solution gives you that, if you start with the inner rectangle.
load mask
mask0=finalMask;
mask=imclose(mask0,ones(15,1));
A=bwconvhull(mask)&~mask; %deliberate here, but unnecessary. Just start with inner rectangle.
A=max(0, 1-bwdist(A)/5);
A( abs( conv2(A,ones(3)/9,'same')-1)<=1e-6)=0;
A=A.*mask0;
imshow(A)
Worked like a charm with the first code that you shared using only the internal boundary. Thanks.

Sign in to comment.

More Answers (0)

Categories

Find more on Programming in Help Center and File Exchange

Asked:

on 20 Dec 2021

Commented:

on 21 Dec 2021

Community Treasure Hunt

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

Start Hunting!