Overlapping rectangles problem in an image

4 ビュー (過去 30 日間)
Mayank Nautiyal
Mayank Nautiyal 2019 年 9 月 4 日
コメント済み: darova 2019 年 9 月 4 日
I am creating an 8-bit image with non-overlapping rectangles.
I'm using I=ones(256,256) to create a matrix with all 1's.
Now I have to create random rectangles inside the image such that they do not overlap.
My Idea is: First create a random rectangle by I(x:x+length,y:y+length)=0; then start a loop which checks whether the new x and y have pixel value 0. If it is 0 it means that the new rectangle is starting inside my previous rectangle. If not, it will create new rectangles until the loop terminates.
Note: I need algorithm not code as I am learning how to code in Matlab.
I am using randi to generate x and y : x=randi( [1,255] ,1)
  1 件のコメント
darova
darova 2019 年 9 月 4 日
Do you have any attempts? What have you tried?

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

回答 (1 件)

darova
darova 2019 年 9 月 4 日
Use inpolygon() to check if point is in rectangle
  1 件のコメント
Mayank Nautiyal
Mayank Nautiyal 2019 年 9 月 4 日
cannot use inbuilt functions

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

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by