How to segment a matrix into N regions with sizes XYZ?

6 ビュー (過去 30 日間)
Neurolab
Neurolab 2024 年 1 月 31 日
回答済み: Pratik 2024 年 2 月 13 日
Hi everyone,
I have a matrix (i.e. 100 x 100, but the shape may vary) and I want to segment it into contiguous regions with specific numbers of elements. So for example 3 contiguous regions, with sizes equal to 2450, 3350 and 4200 elements. As if the matrix had been segmented by k-means but into regions with these exact areas.
Ideally I would also like have some control over roughly where these regions are formed around (i.e. I would like to give 3 points, one of which must be contained within each region), but this is not so important.
This is part of an image segmentation process where we detect N segments in an image and want to recreate a facsimile image with the same number of segments with the same areas.
I have coded an iterative process which starts with N starting points and adds elements to each one consequtively until the whole image is filled, but this is not fast enough and also does not replicate the original segments very well.
I could assign values to a matrix (i.e. 2450 1s, 3350 2s, 4200 3s) based on linear indices but then the resulting segments would be very blocky and may not be contiguous. I could assign these values to random positions and then iteratively move them to congregate around specific points, but that would likely also be a slow process.
Is there such a thing as a 2D topographical sorting algorithm?
Thanks for any help.
  10 件のコメント
Matt J
Matt J 2024 年 2 月 1 日
編集済み: Matt J 2024 年 2 月 1 日
Can you not introduce a surrounding squish region whose area you would allow to change? Affine transformations can be designed that preserve straight lines, area, and boundary continuity (so most of the properties you've mentioned) but forcing them also to respect the same rectangular image boundaries is probably a tall order.
Neurolab
Neurolab 2024 年 2 月 1 日
No, unfortunately not.

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

回答 (1 件)

Pratik
Pratik 2024 年 2 月 13 日
Hi Neurolab,
As per my understanding, you want to segment a matrix into N regions with predetermined sizes. You have few approaches for the same and a common issue with them is the speed of the algorithm.
Segmenting a matrix into contiguous regions with specific sizes is an interesting challenge, particularly if you want to control where the regions form. There is no built-in function in MATLAB as of now that can do this.
For an efficient solution, you might consider implementing your algorithm in a compiled language like C++ and call it from MATLAB using a MEX-function.
Please refer to the following documentation for more information on creating high-performance functions, implemented in modern C++, that can be called from MATLAB:
Also, documentation about best practices for using MEX Functions to Accelerate MATLAB Algorithm can be referred:
I hope this helps!

カテゴリ

Help Center および File ExchangeGeometric Transformation and Image Registration についてさらに検索

製品


リリース

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by