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

1 回表示 (過去 30 日間)
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 件のコメント
waqas
waqas 2021 年 12 月 20 日
Sorry, I have corrected the mistake in the post.
Matt J
Matt J 2021 年 12 月 20 日
Very good. Then see my answer below.

サインインしてコメントする。

採用された回答

Matt J
Matt J 2021 年 12 月 20 日
編集済み: Matt J 2021 年 12 月 20 日
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 件のコメント
Matt J
Matt J 2021 年 12 月 20 日
編集済み: Matt J 2021 年 12 月 20 日
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)
waqas
waqas 2021 年 12 月 21 日
Worked like a charm with the first code that you shared using only the internal boundary. Thanks.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeImages についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by