Python Forum
How to extract (x,y) coordinates of the boundary of a .tif image?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to extract (x,y) coordinates of the boundary of a .tif image?
#21
if i were to do this based on knowing nothing more, i'd take the RGB color image and make a monochrome image, if color is what i get.  i'd pick some value like 0xb0 and use that as the black (anything less) vs. white (anything greater) test. then i'd trace around looking for pixels with neighbors of the opposite value.  this makes for a 2-pixel boundary.  i don't (yet) know what to do (next) to get a (correct) 1-pixel boundary.  it probably depends on what the boundary is to be used for and how it will be used to make these decisions.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#22
It's propably not fair to ask whether you throwed a glance to the code I've postet... Blush
Only that I stayed in the monochromatic range until now. well, okay, I also did the colour check more mathematically.
Reply
#23
to be honest, i did not look at the code.   i regularly skip that unless it is very small.  i prefer to take a more abstract view for issues in things like this.  i'd look at code if the issue is about something like a code expression not doing what is expected.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#24
First, the RGB-type for the human pattern recognition part:
rgbimage = imac.convert("RGB")
areacol = rgbimage.getpixel((imsize[0] - 1, imsize[1] - 1))

for provenpix in provenpixels:
    rgbimage.putpixel(provenpix, (0, 200, 200))
for stillunprovpix in remainingunclear:
    rgbimage.putpixel(stillunprovpix, (200, 200, 0))
  
for stillunprovpix in remainingunclear:
    rgbimage.putpixel(stillunprovpix, (255, 0, 0))
    rgbimage.show()
    print "Is this a border pixel? It has the coordinates: ", stillunprovpix
    while True: 
        pixelinfo = raw_input("yes (y) or no (n)? ")
        if pixelinfo in ("y", "ye", "yes"):
            provenpixels.append(stillunprovpix)
            rgbimage.putpixel(stillunprovpix, (0, 125, 125))
            break
        elif pixelinfo in ("n", "no"):
            rgbimage.putpixel(stillunprovpix, areacol)            # remove mark
            break
Second...As I said, the code does mostly what you propose.
Only this part I don't understand:
(Feb-18-2017, 04:58 AM)Skaperen Wrote:  it probably depends on what the boundary is to be used for and how it will be used to make these decisions.

If "1-Pixel-border" is only what I assume it to be, there is no difference depending on the usage. It's just a question of "is this pixel one that makes the demarcation between the both colour regions?" 

And if you like to think about patterns: How would you solve a region like this in universal rules? I was not able to get a "full" solution.
Bit of ASCII art, "x" is black (background color) and "-" is blue (area colour):

xxxxxxxxxx-
xxxxxxx----
---xxxxx---
--xxxxxxx--
--xxxxxxx--
---xxxxxx--
-----------
With checking a maximum of 8 neighbours, I was able to prove the border state of a couple of pixels, shown here as "o":

xxxxxxxxxxo
xxxxxxxoo--
oooxxxxxo--
--xxxxxxx--
--xxxxxxxo-
---oxxxxx--
----oooo---
Switching to "o" for the pixels with unproven border state:

xxxxxxxxxx-
xxxxxxx--o-
---xxxxx---
--oxxxxxxo-
--oxxxxxx--
---xxxxxxo-
--------o--
I fear one has to widen up the range of neighbours to a total of at least 15 for those...
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Get the image's coordinates not the canvas' when navigate on an image hobbyist 9 1,825 Jul-21-2022, 03:29 PM
Last Post: deanhystad
  Crop Image to Bounding Box Coordinates sallyjc81 2 5,025 Jul-23-2020, 08:46 AM
Last Post: sallyjc81
  periodic boundary contions grknkilicaslan 1 1,898 Jul-18-2020, 10:16 PM
Last Post: Gribouillis
  How to extract temperature value of pixels of a thermal image recorded by IR camera hamacvan 1 14,436 Jan-13-2019, 06:06 PM
Last Post: Larz60+
  How to extract digits in table of image using python SuSeegio 3 3,075 Dec-05-2018, 10:47 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020