maximum square inside a contour

Pratap Vardhan pratapgr8 at gmail.com
Thu Apr 28 13:41:58 EDT 2016


If I understand it correctly -- here's one approach using morphological 
operators. 

1. Take centroid as seed point (new image).
2. Dilate it with 3x3 structuring element.
3. Check if union of seed image and contour image has created new pixels 
(i,e to check if square touched the contour)
4. If not, repeat step 1-2-3 till 3 is met.

That should give you largest possible square? I used similar approach for 
flooding problem and maze 
solving. https://www.youtube.com/watch?v=jhL8uELbVIM

Regards,
Pratap


On Thursday, April 28, 2016 at 11:01:59 PM UTC+5:30, Jaime Lopez Carvajal 
wrote:
>
> Hi Georges,
>
> I really don't have the green square, it is what I want to get. I just put 
> it there for illustration purpouses.
>
> But you give an interesting point of view. I will start from centroid, 
> checking in every step if every square's corner is inside the region (as 
> you said, 0 value)
> it they are inside, increase their coordinates respectively, if not, take 
> coordinates from the previous step to build the square.
>
> I will give it a try, and will say how it works,
>
> Thanks, Jaime
>
> On Thursday, April 28, 2016 at 12:46:42 PM UTC-4, GeorgesVis wrote:
>>
>> How about turning problem into an optimisation problem ?
>> You have the green square, could be considered as initial maximum square 
>> dimensions.
>>
>> I believe it can be done by varying the position of the square along a 
>> path that maximises the square dimensions while all px values remain at 0 
>> (ubyte image).
>> The path can be chosen depending on the polygon properties, if it is a 
>> platonic solid you use mass centre or the positions along the symmetry axis 
>> (example above).
>>
>> Else, a more expensive approach: pick random positions (pos) and keep 
>> same size. Check if all px==0: increase size; else: continue to next pos.
>> I think you should also look at the flood fill algorithm, could also be 
>> helpful.
>>
>>
>> Hope this helps. 
>> Cheers, Georges
>>
>> On Monday, 25 April 2016 13:30:21 UTC-7, Jaime Lopez Carvajal wrote:
>>>
>>> Hi friends,
>>>
>>> Someone knows how can I find a maximum square inside a contour, giving 
>>> as parameter the centroid point? 
>>> I need whole square area fall inside the contour. Any advice?
>>>
>>> Thanks in advance, Jaime
>>>
>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/scikit-image/attachments/20160428/bf644005/attachment.html>


More information about the scikit-image mailing list