Gimptalk - Premier Gimp Community: Thin 1 bit (B&W) image shapes down to 1 pixel wide ? - Gimptalk - Premier Gimp Community

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Thin 1 bit (B&W) image shapes down to 1 pixel wide ?

#1 User is offline   gimptowns 

  • Newbie
  • Pip
  • Group: Members
  • Posts: 6
  • Joined: 19-March 11

Posted 19 March 2011 - 11:49 AM

Hi,

I love Gimp and it seems to do most things to an image. However, I can't find a way for it to mimic a 'thin' of a 1 bit black and white image.

Specifically, I want it to be able to remove black pixels from the edges of any black shapes until there is only one pixel width left. This is very useful if you want to know image line paths but don't want more than one pixel for them. (Ideally you could also pick how many pixel removing iterations you do which could therefore affect the amount of 'thinning').

I've been through most processes in Gimp but am I missing something?

Anyone have any suggestions?

Thanks !
0

#2 User is offline   PhotoComix 

  • GT Senior Moderator
  • Group: Senior Moderators
  • Posts: 11,288
  • Joined: 13-June 05

Posted 20 March 2011 - 12:27 AM

Basically you want get only the edges, the contours from a 1bit images, let say removing the black fill from the black part except from their border?

If so should be easy

1 ) if is indexed to 1bit first do Image/image mode/rgb (because many gimp tools don't work well with index images)
this will change nothing in the look of your image

2) Select by color the black (or the white as you like) set the treeshold to get the best result

3) selection to path

4) create a new white layer

5) stroke the path ,chose 1px wide line

could be a problem since pixel are square 1pixel lines could look very jagged (except horizontal and vertical lines )
0

#3 User is offline   gimptowns 

  • Newbie
  • Pip
  • Group: Members
  • Posts: 6
  • Joined: 19-March 11

Posted 20 March 2011 - 12:55 PM

Thanks PhotoComix - that is similar but it would leave two, one pixel lines on the outside of the original line.

What I want to do is to select a polygon area and then erode within it from all sides. When this is done, a line would remain a line but would be 1 pixel wide.
0

#4 User is offline   DMJY 

  • Newbie
  • Pip
  • Group: Members
  • Posts: 4
  • Joined: 21-March 11

Posted 22 March 2011 - 03:17 AM

what will be different,can you explain it ?
0

#5 User is offline   gimptowns 

  • Newbie
  • Pip
  • Group: Members
  • Posts: 6
  • Joined: 19-March 11

Posted 22 March 2011 - 01:17 PM

Hi DMJY, thanks for the reply.

What I want is a 1 pixel centered 'skeleton' shape of the original.

As far as I can see, PhotoComix's method would produce an outline of the shape.

I'm not sure of the actual pixel iteration for this 'skeleton' but you could Loop it and it would be something like this:

................
In X direction
(If current black pixel is surrounded by white pixels in Y direction then do not remove it).
If number of continuous black pixels in X direction are greater than 3 then remove first and last pixel.
If number of continuous black pixels in X direction are equal to two then remove first pixel.

In Y direction
(If current black pixel is surrounded by white pixels in X direction then do not remove it).
If number of continuous black pixels in Y direction are greater than 3 then remove first and last pixel.
If number of continuous black pixels in Y direction are equal to two then remove first pixel.
................
0

#6 User is offline   rich2005 

  • Member
  • PipPip
  • Group: Members
  • Posts: 323
  • Joined: 01-December 10

Posted 22 March 2011 - 03:29 PM

Is this what you are trying? Read and reread your algorithm - thinks it means this.

Posted Image


Its small because I attempted a manual procedure. Started with a random-ish black image, selected, then progressively shrank and cut 1 pix at a time (changing colour to get the banded effect). Stopped when any further reduction would change the basic shape. Then grow 1 pix to get the outline. (copied & moved the final outline, for demo.)

If this is what you want, should not be beyond one of the script gurus
0

#7 User is offline   PhotoComix 

  • GT Senior Moderator
  • Group: Senior Moderators
  • Posts: 11,288
  • Joined: 13-June 05

Posted 22 March 2011 - 03:32 PM

Do you mean something similar to what discussed here http://homepages.inf.../HIPR2/thin.htm ?

that is also know as skeleton filter ?
if so it is inclòuded in the Gmic plugin,
once installed gmic you will found in the gmic filter list under contourn/ Skeletron
0

#8 User is offline   gimptowns 

  • Newbie
  • Pip
  • Group: Members
  • Posts: 6
  • Joined: 19-March 11

Posted 22 March 2011 - 05:19 PM

rich2005 - thanks very much for having a go with the iteration!

Your image is almost right but I am talking black and white (1 bit) and the filter should probably leave the original lines in. (Having said that my procedure is probably not 100% unfortunately!).

PhotoComix - the link to Thinning that you gave is completely what I'm after - many thanks!

Figure 2 on that page shows the Before and After that I want (I am considering the 1 pixels as black):

Posted Image

It appears that Skeletonization is very similar to Thinning and involves working out the centerline instead of the Morphology.

Anyway, I loaded G'mic. The Skeletonization does the job but I have to invert the image first. No problem there but it then takes a very very long time to work on any image of size. I guess Skeletonization is more processor intensive than Thinning.

I then look through G'mic for Morphological Thinning and unless I'm missing something I don't think it has it.

I guess now I've either got to work out if that Morphological Thinning you showed me is elsewhere or can be added?

Any suggestions most welcome!
0

#9 User is offline   PhotoComix 

  • GT Senior Moderator
  • Group: Senior Moderators
  • Posts: 11,288
  • Joined: 13-June 05

Posted 22 March 2011 - 07:09 PM

Quote

Anyway, I loaded G'mic. The Skeletonization does the job but I have to invert the image first. No problem there but it then takes a very very long time to work on any image of size. I guess Skeletonization is more processor intensive than Thinning.


yes is a quite intensive filter

Quote

but I have to invert the image first


No problem here if you need inverted i may well add a invert option to the filter
you need only to tell me if you intend to use the command line gmic or the plugin, or both

For me would be a really easy and quick so don't worry, but if you wish that please post herewith a title as Skeleton Filter or i may forgot (bad memory )
http://www.flickr.co...s/gmic/discuss/
May be ready tonight but you will have to install as a extra gmic filter (i may link the how to )

Quote

I then look through G'mic for Morphological Thinning and unless I'm missing something I don't think it has it.
I guess now I've either got to work out if that Morphological Thinning you showed me is elsewhere or can be added?
Any suggestions most welcome!


No idea, may be already in gmic with a different name
And in theory can be added but for sure not by me... will be far beyond my skills
Anyway you may request ,same link for the GMIC group there search there for the "wishlist" topic, and post there
0

#10 User is offline   PhotoComix 

  • GT Senior Moderator
  • Group: Senior Moderators
  • Posts: 11,288
  • Joined: 13-June 05

Posted 22 March 2011 - 07:20 PM

ah there is also this web app
http://homepages.inf...R2/thindemo.htm
0

#11 User is offline   DMJY 

  • Newbie
  • Pip
  • Group: Members
  • Posts: 4
  • Joined: 21-March 11

Posted 23 March 2011 - 12:51 AM

thank you for answering the question,I appreciate it very much.you reply it very quickly.thanks again,I have got the difference.
0

#12 User is offline   gimptowns 

  • Newbie
  • Pip
  • Group: Members
  • Posts: 6
  • Joined: 19-March 11

Posted 23 March 2011 - 07:09 PM

Thanks all for the links and help people.

I've played some more and it seems to me that there are two ways to get a 'thinned' 1 bit image:

1. 'Skeletonization' which may use the 'Distance Transform' method. This is available in G'mic as a separate 'Skeletonization' filter. The downside with this filter is that you have to invert the image and it is extremely slow (almost unusable) with large images.

2. 'Morphological Thinning' which uses a 'Hit and Miss Transform' on each pixel to get the thinning effect. G'mic does have morphological filters and the 'Erosion' filter works well and is fast. Unfortunately there is neither an option to Thin nor an option to not Erode single pixels.

This is the definition of Morphological Thinning as applied to each pixel:
Posted Image
Figure 1 Structuring elements for skeletonization by morphological thinning. At each iteration, the image is first thinned by the left hand structuring element, and then by the right hand one, and then with the remaining six 90° rotations of the two elements. The process is repeated in cyclic fashion until none of the thinnings produces any further change. As usual, the origin of the structuring element is at the center.

Photocomix, I'm using Gimp G'mic plugin. I can see that you have had a hand in G'mic - well done.

I wonder how difficult it would be to either get the Erode function modified, or a Thinning option added to G'mic Morphological Filters ?
0

#13 User is offline   PhotoComix 

  • GT Senior Moderator
  • Group: Senior Moderators
  • Posts: 11,288
  • Joined: 13-June 05

Posted 24 March 2011 - 12:23 PM

View Postgimptowns, on 23 March 2011 - 07:09 PM, said:


I wonder how difficult it would be to either get the Erode function modified, or a Thinning option added to G'mic Morphological Filters ?


Usually just post the wish and the motivations on the flickr Gmic group, may be sufficent to see the update in a few days
(not 100% sure of course but if the request is well motivated and there are no tecnichal obstacles, good chance will be done quickly )

And invert the output of the skeletron filter will take me no more of the the time to needed add

-n

close to the end of the filter code,... so really not much time
0

#14 User is offline   gimptowns 

  • Newbie
  • Pip
  • Group: Members
  • Posts: 6
  • Joined: 19-March 11

Posted 24 March 2011 - 02:01 PM

Thanks PhotoComix.

I'll put it on the Flickr group.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic