It is currently 12 Aug 2020, 07:03

• Featuring Members' Works (Image Attachments) •
1: member
2: member
3: member
4: member
5: member

GIMP/GL:  Tutorials | Tips | 🡆 Questions | Interests | Script Requests
Recommendations:  Index | Top 10
Resources:  Python-Fu Plug-ins | Scheme-Fu Scripts | GIMP
Python:  Lessons | Questions | Exercises
The Arts:  GIMPed | GIMPed Photos | Other | Contests | Public Domain Images | Isolated Images | Blender
Inkscape
Social:  Say Hello | Anything Goes | Shares | FCSP

Determine if selection is triangular

GIMP or GIMP LEARN forum related Questions
User avatar
Kris.Nothing
Guests

Determine if selection is triangular

Post#1 by Kris.Nothing » 23 Jul 2020, 18:34


Hi Tim,
is it possible in GIMP Python to determine if a selection is a triangle?
...
0

tim
GL Blogger

Post#2 by tim » 23 Jul 2020, 19:07


Probably if you did enough research and math.
I wouldn't know how though.
aka Tin
:tree_02:
Tin's: Favorite Index | Simple Art === fb4yt video search | fb4yt recent video views report
Lottery numbers from image | Interested Members in TLF
Paying for hosting is to support my hobby, and donating money made from ads to The Red Cross.
         
0

tim
GL Blogger

Post#3 by tim » 23 Jul 2020, 19:29


Just gave this some more thought.
If you take your selection, let's call it ORI or original. get selection bounds which returns bounding box let's call this BOX.
To determine 3 (minimum and maximum) points which possibly be a triangle, intersect the ORI with each selection that is the selection of one side of BOX x 1pixel wide/tall....if you get one pixel back it means it's a single point, if more just ignore
If you end up with exactly 3 points on the boundary of BOX.
Then polygon select these 3 points, which creates a triangle of your own, then intersect with ORI, and get history pixel count ...if it's the same or within some threshold limit that is small then we can say that our selected polygon (triangle) is very close to ORI so ORI can be said to be a triangle.
aka Tin
:tree_02:
Tin's: Favorite Index | Simple Art === fb4yt video search | fb4yt recent video views report
Lottery numbers from image | Interested Members in TLF
Paying for hosting is to support my hobby, and donating money made from ads to The Red Cross.
         
0

tim
GL Blogger

Post#4 by tim » 23 Jul 2020, 19:31


oh never mind that won't cover all cases of triangles as you could have a triangle that has 2 points which touch the bounding box but a 3rd point that is somewhere in middle of bounding box.
aka Tin
:tree_02:
Tin's: Favorite Index | Simple Art === fb4yt video search | fb4yt recent video views report
Lottery numbers from image | Interested Members in TLF
Paying for hosting is to support my hobby, and donating money made from ads to The Red Cross.
         
0

tim
GL Blogger

Post#5 by tim » 24 Jul 2020, 02:21


Gave this some more thought: here's what I would do, it might not be ideal and/or slow but this is what I came up with.
You could look at distances between every possible pair of pixel-location within the selection.
The greatest distance will tell you two points that defines the longest side of the triangle.
Let's call them those two points A and B.
find point C which is also in the selection, but where the sum of (the distance between A and C + the distance between B and C)
if maximum.
This will give you third point of triangle (possibly).
Now select polygon ABC.
Intersect with your original selection, get pixel count using histogram something method in GIMP. and compare to pixel count of original selection.
If it's similar or very close then you know you have a triangle or very close to one.

The first part looking for pairs of pixels can be sped up by getting selection bounding box, then intersect with 1pixel wide sides
to check for A and B. since a triangle will always have 2 points that define the longest side on the boundary of the bounding box.
aka Tin
:tree_02:
Tin's: Favorite Index | Simple Art === fb4yt video search | fb4yt recent video views report
Lottery numbers from image | Interested Members in TLF
Paying for hosting is to support my hobby, and donating money made from ads to The Red Cross.
         
0

User avatar
Kris.Nothing
Guests

Post#6 by Kris.Nothing » 24 Jul 2020, 08:56


Hi Tim,

Thanks for the food for thought.
I'll see what I can do with it.
Thanks
...
0

tim
GL Blogger

Post#7 by tim » 24 Jul 2020, 11:54


What are you trying to accomplish in the bigger picture (if you don't mind me asking).
Maybe there are other ways to do the bigger task.
aka Tin
:tree_02:
Tin's: Favorite Index | Simple Art === fb4yt video search | fb4yt recent video views report
Lottery numbers from image | Interested Members in TLF
Paying for hosting is to support my hobby, and donating money made from ads to The Red Cross.
         
0

User avatar
Kris.Nothing
Guests

Post#8 by Kris.Nothing » 24 Jul 2020, 14:14


I want the user to make a triangular selection in one of the 4 corners of an image ( as a prerequisite of a "corner script")
I can test for selection being there, but can I make sure it's a triangle and not a polygone or circle or something?
Probably overdone ... but it keeps me thinking if it were possible at all.
...
0

tim
GL Blogger

Post#9 by tim » 24 Jul 2020, 20:25


is it always going to be an actual triangle that covers a corner.
If so I would just allow options for user to choose NW,NE,SW,SE ...then they specify height and width of triangle and do the selection in the script yourself.
aka Tin
:tree_02:
Tin's: Favorite Index | Simple Art === fb4yt video search | fb4yt recent video views report
Lottery numbers from image | Interested Members in TLF
Paying for hosting is to support my hobby, and donating money made from ads to The Red Cross.
         
0


GIMP/GL:  Tutorials | Tips | 🡆 Questions | Interests | Script Requests
Recommendations:  Index | Top 10
Resources:  Python-Fu Plug-ins | Scheme-Fu Scripts | GIMP
Python:  Lessons | Questions | Exercises
The Arts:  GIMPed | GIMPed Photos | Other | Contests | Public Domain Images | Isolated Images | Blender
Inkscape
Social:  Say Hello | Anything Goes | Shares | FCSP

Post Reply
  • Similar Topics
    Replies
    Views
    Last post

Who is online

Users browsing this forum: No registered users and 6 guests