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 commentaires

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)
Sorry, I have corrected the mistake in the post.
Very good. Then see my answer below.

Connectez-vous pour commenter.

 Réponse acceptée

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 commentaires

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.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Programming dans Centre d'aide et File Exchange

Question posée :

le 20 Déc 2021

Commenté :

le 21 Déc 2021

Community Treasure Hunt

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

Start Hunting!

Translated by