0
A
答えて
0
私はあなたがほしいと思うものはPolygon Fillingです。しかし、ポイントとエッジをソートして、すべてを埋める必要があります。
他の簡単な解決策は、すべての黒色成分(Union-Findアルゴリズム)にラベルを付け、境界に触れないものに色を付けることです。
+0
@FiReRiRi、ありがとうございます! – Vlad
0
次の解決策は、あなたの星であるポリゴンの角を知ることに基づいています。その場合、poly2mask
を使用して、星の内側(および境界線)に対応する塗りつぶしのピクセル(値1
)と星の境界の外側の空のピクセル(値0
)を持つ行列を生成できます。
など。
function filledStar = createFilledStar(boxSize)
%// center star in box
xCenter = boxSize/2;
yCenter = xCenter;
%// setup: star with random rotation
angles = (rand + (0:1/10:1))*2*pi; %// polygon corners, angle
rOuter = boxSize*0.5; %// star outer radius
rInner = boxSize*0.2; %// star inner radius
%// generate star polygon corner coordinates
r = [repmat([rOuter rInner],1,5), rOuter];
x = xCenter + r.*cos(angles);
y = yCenter - r.*sin(angles);
%// convert polygon to 0-1 mask (as double) in box
starMask = double(poly2mask(x, y, boxSize,boxSize));
%// (if you'd like to smooth edges), apply gaussian and return
filledStar = imgaussfilt(starMask,1);
end
boxSize = 500; %// 500x500 pixels
filledStar = createFilledStar(boxSize);
imagesc(filledStar), colormap gray, axis equal
0
として、あなたはこのコードを使用することができます事前に構築されたMATLAB関数を使用しない場合。境界であり、unfill垂直水平にし、「水平に見ることができない」という部分を星を埋める基本的にコードチェック
I = im2bw(imread('image.png'));
hliml = zeros(1,size(I,1));
hlimr = zeros(1,size(I,1));
vliml = zeros(1,size(I,2));
vlimr = zeros(1,size(I,2));
for i = 1:size(I,1)
if ~isempty(find([diff(I(i,:)),0]==1,1,'first'))
hliml(i) = find([diff(I(i,:)),0]==1,1,'first');
end
if ~isempty(find([diff(I(i,:)),0]==-1,1,'last'))
hlimr(i) = find([diff(I(i,:)),0]==-1,1,'last');
end
end
for i = 1:size(I,2)
if ~isempty(find([diff(I(:,i));0]==1,1,'first'))
vliml(i) = find([diff(I(:,i));0]==1,1,'first');
end
if ~isempty(find([diff(I(:,i));0]==-1,1,'last'))
vlimr(i) = find([diff(I(:,i));0]==-1,1,'last');
end
end
for i = 1:size(I,1)
if hliml(i)~=0
I(i,hliml(i):hlimr(i)) = 1;
end
end
for i = 1:size(I,2)
if vliml(i)~=0
I(1:vliml(i),i) = 0;
I(vlimr(i):end,i) = 0;
end
end
imshow(I);
関連する問題
- 1. クリップボックスシャドウは、方法はあり現在鉱山が</p> <p><a href="https://i.stack.imgur.com/xDug1.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xDug1.png" alt="enter image description here"></a></p> <p>下の画像のように見える
- 2. この絵<img src="https://i.stack.imgur.com/LPic0.png" alt="enter image description here"></p> <p>で見える
- 3. ... <p><a href="https://i.stack.imgur.com/g7lSe.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/g7lSe.png" alt="enter image description here"></a></p> <p></p>が、私は以下のコードを試してみました。.. CollectionViewコントローラ画像以下のような
- 4. ウェブスクレイピング - Angular.js経由でJavaScriptでレンダリングされたコンテンツにアクセスする方法は?</p> <p><a href="https://i.stack.imgur.com/Siny9.png" rel="noreferrer"><img src="https://i.stack.imgur.com/Siny9.png" alt="enter image description here"></a></p> <p>しかし:
- 5. 助言:ドラッグドロップは、私が<a href="http://scratch.mit.edu/" rel="nofollow noreferrer">MIT's Scratch</a></p> <p><img src="https://i.stack.imgur.com/h7MIQ.gif" alt="enter image description here"></p> <p>のように動作し、iPhoneやiPadのアプリを構築したい
- 6. は、これはどのように</p> <p><img src="https://i.stack.imgur.com/q1ySm.png" alt="enter image description here"></p> <p>私は何をすべき...
- 7. イメージ上でユーザーの場所をプロット(表示)する方法は?このような画像に</p> <p>を表示するユーザの現在位置:</p> <p><img src="https://i.stack.imgur.com/qwHBH.jpg" alt="enter image description here"></p> <p>はい、この画像のようなので、ここでのiOS
- 8. は、Drupalの7では8</p> <p><a href="https://i.stack.imgur.com/vlXrm.png" rel="noreferrer"><img src="https://i.stack.imgur.com/vlXrm.png" alt="enter image description here"></a></p> <p>Drupalのフロントページのヘッダータイトルからあなただけのpage.tpl.phpでのコードのこの部分を追加し、「ようこそ」削除する方法はDrupal 8
- 9. 、チーム - >上流にプッシュして、ストリームアップからのフェッチ、コミットすることができたり、押していないことイム後 <a href="https://i.stack.imgur.com/TCbN9.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/TCbN9.png" alt="enter image description here"></a></p> <p>Gitのステージングビューアで
- 10. は、添付された画像<img src="https://i.stack.imgur.com/vCKqH.png" alt="enter image description here"></p> <p>に示すように、画像のiOS SDK
- 11. このテキストを拡大して縦の領域を拡大し、その横の領域を減算する方法私は青/紫のテキストが水平に小さく、縦に大きいですしたい<a href="https://i.stack.imgur.com/7ixpq.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7ixpq.png" alt="enter image description here"></a></p> <p>:
- 12. は、私は私はそれがD3で利用できないと思う<a href="http://dynamicdatadisplay.codeplex.com/" rel="nofollow noreferrer">D3</a></p> <p><img src="https://i.stack.imgur.com/NuQXS.png" alt="enter image description here"></p> <p>を使用して、このようなステップ折れ線グラフがしたいの動的データ表示
- 13. のImageMagick:この中へ</p> <p><a href="https://i.stack.imgur.com/Va9vo.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Va9vo.jpg" alt="enter image description here"></a></p> <p>:画像
- 14. エラー私は</p> <p></p> <p><a href="https://i.stack.imgur.com/aIxqc.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/aIxqc.jpg" alt="enter image description here"></a>エラーを作成発生かみそりMVCプロジェクトを作成しようとしています
- 15. <HREFまたは<ASP:私の実行、 <img src="https://i.stack.imgur.com/SgRAe.png" alt="enter image description here"></p> <p>ので:ハイパーリンク.....タグは、ランタイム
- 16. JDialogの[3]</p> <p><a href="https://i.stack.imgur.com/c1yEt.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/c1yEt.jpg" alt="enter image description here"></a></p> <p>以上の相互作用後JDialogのが終了小さい毎回がフローティングに/処分
- 17. </p> <p><img src="https://i.stack.imgur.com/cqb1T.png" alt="enter image description here"></p> <p>この画像によう 私は、現在の地域の私の四隅の長いと緯度を知る必要があり、Googleは
- 18. 2つの異なるUIToolbarsが異なるスタイルにデフォルト設定されているのはなぜですか?これらのツールバーが異なって見えること</p> <p><img src="https://i.stack.imgur.com/xpUYa.png" alt="enter image description here"> <img src="https://i.stack.imgur.com/YXbAQ.png" alt="enter image description here"></p> <p>お知らせ:
- 19. Firebaseこれは私のデータベース</p> <p><a href="https://i.stack.imgur.com/xOclS.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xOclS.png" alt="enter image description here"></a></p> <p>ある
- 20. Djangoマルチ選択ウィジェット?私は自分のアプリケーションでこのウィジェットを利用することができますどのように</p> <p><img src="https://i.stack.imgur.com/ybe24.png" alt="enter image description here"></p> <p>:
- 21. gitlabにSSH鍵を追加するにはどうしたらいいですか?</p> <p><a href="https://i.stack.imgur.com/trDuT.png" rel="noreferrer"><img src="https://i.stack.imgur.com/trDuT.png" alt="enter image description here"></a></p> <p>SSHキーを追加する方法は本当にわからない。ここで
- 22. カスタム私はこの</p> <p><img src="https://i.stack.imgur.com/iaGSo.png" alt="enter image description here"></p> <p><img src="https://i.stack.imgur.com/7fvsi.png" alt="enter image description here"></p> <p>のように見えるフィルタリングでコンボボックスを作成する必要があるコンボボックス
- 23. 色の範囲を別の色に簡単に変換できますか?以下のような青に</p> <p><img src="https://i.stack.imgur.com/4Pg2L.jpg" alt="enter image description here"> :私はこの画像では紫の色を変換したい
- 24. 変更特定の単語のテキストの背景色を<p>私は<code>TextView</code>に特定の単語の背景色を変更したい:</p> <p></p> <p><a href="https://i.stack.imgur.com/4I6Sg.png" rel="noreferrer"><img src="https://i.stack.imgur.com/4I6Sg.png" alt="enter image description here"></a></p>
- 25. 2にアンドロイドスタジオ1をアップグレードした後、私は <p><a href="https://i.stack.imgur.com/AqxlY.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/AqxlY.png" alt="enter image description here"></a></p> <h1>Androidのスタジオ版</h1>を取得
- 26. EditorTemplate。コードで</p> <p><img src="https://i.stack.imgur.com/FNOz8.png" alt="enter image description here"></p> <p>:MVC3
- 27. ダイナミックコンポーネントは、上の写真で</p> <p><a href="https://i.stack.imgur.com/abdWR.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/abdWR.png" alt="enter image description here"></a></p> <p>、掲示板での広告で例えば
- 28. 私はないです私は <a href="https://i.stack.imgur.com/S7Sy1.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/S7Sy1.jpg" alt="enter image description here"></a></p> <p>のような他の列の列の値のランニングカウントを計算する必要がありませにSYBASE
- 29. この拡張は</p> <p><a href="https://i.stack.imgur.com/kM51k.png" rel="noreferrer"><img src="https://i.stack.imgur.com/kM51k.png" alt="enter image description here"></a></p> <p>と私のphpinfo()に...
- 30. は私がマップ上のすべてのマーカーを表示することができています<a href="https://i.stack.imgur.com/tlKOr.png" rel="noreferrer"><img src="https://i.stack.imgur.com/tlKOr.png" alt="this"></a></p> <p>のようなものを見せたい
ます[flood-fill](https://en.wikipedia.org/wiki/Flood_fill)アルゴリズムを自分で実装することができます。これが 'imfill'関数の動作です。 – Amro
ありがとう、私はまた、最初の白から最初の黒まで、ピクセルのシーケンスを白に塗りつぶすループについて約2つ考えました。それを行う他の方法はありますか? – Vlad
ドキュメントを引用するには: 'BW2 = imfill(BW、 'holes')はバイナリイメージBWに穴を埋めます。この構文では、穴は、画像の端から背景を塗りつぶすことによって到達できない背景ピクセルのセットです。例えば:http://stackoverflow.com/a/1717015/97160 – Amro