It is currently Thu Apr 18, 2024 5:41 pm


All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 13 posts ] 
Author Message
 Post subject: Removing yellow objects from an image whilst keeping the blue objects
PostPosted: Wed Oct 01, 2014 2:50 am  (#1) 
Offline
New Member

Joined: Sep 30, 2014
Posts: 4
Hi to all who read this

I am fairly new to GIMP and know what to do to get my images the way I want them, my problem is writing a macro to aid me in doing this to hundreds of additional images. Im used to simple macro scripting where you just record, this is on a whole new level. If someone really knows how, please can you help with the scripting of the following. The image will be open in GIMP prior to the following:

1) Decompose the image to LAB, the decompose to layers must be checked)
2) Switch off the L channel in the new image
3) Select the A channel
4) Set paint color to 50% grey
5) Fill the whole A channel with 50% grey using the bucket tool
6) Switch off A channel and select B channel
7) Stretch Contrast of the B channel
8) Switch on the A and B channels
9) Compose to LAB
10) Decompose new image to RGB
11) Delete the R and G channels

Well, thats it.. Any help would be greatly appreciated.
I have attached a tiff file as an example of what I am currently working on.
Thank you


Attachments:
File comment: Epi-fluorescent staining of bacterial cells (blue) and the auto-fluorescent sediment (yellow).
1.tif
1.tif [ 3.54 MiB | Viewed 6155 times ]
Share on Facebook Share on Twitter Share on Orkut Share on Digg Share on MySpace Share on Delicious Share on Technorati
Top
 Post subject: Re: Removing yellow objects from an image whilst keeping the blue obje
PostPosted: Wed Oct 01, 2014 3:43 am  (#2) 
Offline
Global Moderator
User avatar

Joined: Apr 01, 2012
Posts: 7712
Location: On the other side of this screen
I would like to try to have a go at this but cannot open your file. May be why you haven't any replies yet.

_________________


Top
 Post subject: Re: Removing yellow objects from an image whilst keeping the blue obje
PostPosted: Wed Oct 01, 2014 4:13 am  (#3) 
Offline
New Member

Joined: Sep 30, 2014
Posts: 4
Oh, thats wierd..

I will try to rectify that now..


Top
 Post subject: Re: Removing yellow objects from an image whilst keeping the blue obje
PostPosted: Wed Oct 01, 2014 4:17 am  (#4) 
Offline
New Member

Joined: Sep 30, 2014
Posts: 4
Maybe this will work...

Right clicking and going Save As seems to work, but it doesnt want to open in the page. Maybe because of its large size..


Attachments:
1.tif
1.tif [ 3.54 MiB | Viewed 6087 times ]
Top
 Post subject: Re: Removing yellow objects from an image whilst keeping the blue obje
PostPosted: Wed Oct 01, 2014 5:43 am  (#5) 
Offline
Global Moderator
User avatar

Joined: Apr 01, 2012
Posts: 7712
Location: On the other side of this screen
Followed your instructions and came up with this. Maybe someone else can help with scripting.
Image

_________________


Top
 Post subject: Re: Removing yellow objects from an image whilst keeping the blue obje
PostPosted: Wed Oct 01, 2014 5:46 am  (#6) 
Offline
New Member

Joined: Sep 30, 2014
Posts: 4
Yes, that is what I need, and I can do that... I need a macro script to do that a few hundred times over.

Doing it manually will just take forever!...


Top
 Post subject: Re: Removing yellow objects from an image whilst keeping the blue obje
PostPosted: Wed Oct 01, 2014 5:49 am  (#7) 
Offline
Global Moderator
User avatar

Joined: Apr 01, 2012
Posts: 7712
Location: On the other side of this screen
There are a few coders here and one of them will write you a script.

_________________


Top
 Post subject: Re: Removing yellow objects from an image whilst keeping the blue obje
PostPosted: Wed Oct 01, 2014 7:35 am  (#8) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4736
Hmm. Using LAB seems overly complex. LAB is a perceptual thing. Looks like what you what is keep only what has a given Hue and Level. Your processing:

Attachment:
Bacteria-ProcessedToSpec.jpg
Bacteria-ProcessedToSpec.jpg [ 62.77 KiB | Viewed 6019 times ]


1st solution: Decompose to HSV, threshold Hue to only keep the blue, add black background layer, and add layer mask using thresholded Hue:

Attachment:
Bacteria-LayerMaskWithThresholdedHue.jpg
Bacteria-LayerMaskWithThresholdedHue.jpg [ 164.96 KiB | Viewed 6019 times ]


Even simpler and more radical: Change image mode to indexed, with low number of colors (16). Then edit the color map and change every color which isn't blue to black:

Attachment:
Bacteria-ColorIndex16+EditColorMap.jpg
Bacteria-ColorIndex16+EditColorMap.jpg [ 42.37 KiB | Viewed 6019 times ]


The color map has been manually edited above, but that would be quite simple to script...

_________________
Image


Top
 Post subject: Re: Removing yellow objects from an image whilst keeping the blue obje
PostPosted: Wed Oct 01, 2014 7:58 am  (#9) 
Offline
Script Coder
User avatar

Joined: Apr 23, 2010
Posts: 1553
Location: not from Guildford after all
Travis wrote:
7) Stretch Contrast of the B channel

Should this be done using "Colors->Auto->Stretch Contrast" or using the "Auto" button in the "Colors->Levels..." dialog? (The result is slightly different.)

_________________
Any sufficiently primitive technology is indistinguishable from a rock.


Top
 Post subject: Re: Removing yellow objects from an image whilst keeping the blue obje
PostPosted: Wed Oct 01, 2014 7:59 am  (#10) 
Offline
Script Coder
User avatar

Joined: Jun 22, 2010
Posts: 1171
Location: Here and there
Ofnuts' words not withstanding, here's a script which does the process the way you describe it.

It registers itself in the menus at contributed/Travis:
Attachment:
Untitled.png
Untitled.png [ 20.33 KiB | Viewed 6015 times ]


Kevin


Attachments:
kp24_travis.scm [2.55 KiB]
Downloaded 180 times
Top
 Post subject: Re: Removing yellow objects from an image whilst keeping the blue obje
PostPosted: Wed Oct 01, 2014 8:29 am  (#11) 
Offline
GimpChat Member
User avatar

Joined: Mar 15, 2014
Posts: 115
Location: Brooklyn, NY
Hello Travis,

Wecome to Gimp Chat ! :clap
There are a number of ways to skin this critter; I'm one of the G'MIC bigots resources that hang out here in Gimp Chat, so I'm going that route with you. If you don't know what G'MIC is, there is a discussion group here in the scripting branch (G'MIC Discussions) and a web site gmic.sourceforge.net that will give you background. The moving spirit behind the project, known here on GC as Ronounours (David Tschumperlé) is, in real life, a research scientist in the computer vision and visualization field, including medical imaging. One of the serious reasons he wrote the G'MIC framework was to have a image processing pipeline that avoids the common pitfalls of computational artifacts (mach banding, etc) so G'MIC performs all computations in 32 bit floating point. For that reason alone, you should probably work in that environment, because sadly, much of Gimp is still 8 bit, unsigned integer, so chunks of the pipeline lack the numerical precision you (should) prefer. That will change, and hopefully Real Soon Now, but probably not in the next day or two.

Well, in the time that I've written this, your file still hasn't downloaded, so I'm going to have to punt. I'm assuming in colorwheel terms, the transformation you are looking for is something like this:
Untransformed colorwheel -
Image
Blue isolation, translation to grayscale:
Image

The G'MIC filter that rendered this particular transformation looks like this:
#@gimp Blue Filter: blufilter
#@gimp : txt = text("Documentation? You want documentation? HA!!!")
#@gimp : sep = separator()
blufilter :
-e[^-1] "Isolate Blue components via LAB/RGB space modification."
-verbose -
-repeat @#
   -local[$>]
      -rgb2lab[-1]
      -split c
      -fill_color[-2] 0,0,0
      -normalize[-1] -127,127
      -append[-3--1] c
      -lab2rgb[-1]
      -channels[-1] 2
      -luminance[-1]
    -endlocal
-done
-verbose +

This is little more than a translation of your process in G'MIC speak; my temptaton is to rewrite it around -select_color, so that you could specify any number of keep-supress hues. And, in the G'MIC-Gimp plug-in there is an interactive LAB filter based on setting curve profiles, as in the Gimp curve tool, so you need not script anything at all, but for now I think best to keep the solution near to the form as you stated it.

So what to do with this? Assuming you have a basic Gimp, you need to install G'MIC. The simplest way is probably to go over to Partha's Place and fetch a fresh Gimp for your platform; he has pre-installed G'MIC for you. The Official method is to go over to gmic.soureforge.net and fetch the gmic_gimp binary and drop it into your plugin folder. Platform specific instructions may be found on the download page, scroll down a bit until you see the typewriter text copy.
With G'MIC in place, the little code snippet above will go into your personal .gmic folder ($HOME/.gmic on Linux/Mac/Unix-like) or %APPDATA%/gmic (Windows), the repository for your personal G'MIC commands. Upon plugin restart (or upon starting Gimp) you should have G'MIC as the last item on your Gimp filters menu and something called "Blue Filter" Blue filter has no controls, it will work on the current active layer in preview, and transform the current layer upon "Apply/OK"
For lots and lots of files (did you say hundreds?) I would suggest (strongly) fetching the "gmic" binary from gmic.sourceforge.net. That is a stand-alone, command-line oriented interpreter of the G'MIC scripting language. It has its own looping constructs, or, if your more comfortable with shell/Perl/Python scripting, you could call the gmic interpreter as a subprocess.

That's the basics from the G'MIC front. As noted in the outset, there are many ways to skin this. G'MIC gives you a 32-bit floating point pipeline for a minimum of artifacts arising from numeric precision.

Garry


Top
 Post subject: Re: Removing yellow objects from an image whilst keeping the blue obje
PostPosted: Wed Oct 01, 2014 8:36 am  (#12) 
Offline
Script Coder
User avatar

Joined: Apr 23, 2010
Posts: 1553
Location: not from Guildford after all
If you were to install the following macro:

http://chiselapp.com/user/saulgoode/rep ... 9eca85d0bd

then the following command would process all of the ".tif" files in the current directory when run on GNU/Linux or Mac OS X, producing PNG files for output:
gimp -i -b
'(with-files
  "*.tif"
  (let* ((decomp-image (car (plug-in-decompose RUN-NONINTERACTIVE image layer "LAB" TRUE)))
         (decomp-layers (vector->list (cadr (gimp-image-get-layers decomp-image))))
         (output-filename (string-append basename ".png")) )
    (gimp-levels (cadr decomp-layers) HISTOGRAM-VALUE 0 255 1 128 128)
    (gimp-levels-stretch (caddr decomp-layers))
    (plug-in-recompose RUN-NONINTERACTIVE decomp-image -1)
    (gimp-image-delete decomp-image)
    (plug-in-colors-channel-mixer RUN-NONINTERACTIVE image layer FALSE 0 0 0 0 0 0 0 0 1)
    (gimp-file-save RUN-NONINTERACTIVE image layer output-filename output-filename) )
)'

Upon request, I would be willing to describe the changes required to run the macro on a Microsoft OS and/or to produce files other than PNG.

_________________
Any sufficiently primitive technology is indistinguishable from a rock.


Top
 Post subject: Re: Removing yellow objects from an image whilst keeping the blue obje
PostPosted: Wed Oct 01, 2014 10:11 am  (#13) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4736
grosood wrote:
Hello Travis,

Wecome to Gimp Chat ! :clap
There are a number of ways to skin this critter; I'm one of the G'MIC bigots resources that hang out here in Gimp Chat, so I'm going that route with you. If you don't know what G'MIC is, there is a discussion group here in the scripting branch (G'MIC Discussions) and a web site gmic.sourceforge.net that will give you background. The moving spirit behind the project, known here on GC as Ronounours (David Tschumperlé) is, in real life, a research scientist in the computer vision and visualization field, including medical imaging. One of the serious reasons he wrote the G'MIC framework was to have a image processing pipeline that avoids the common pitfalls of computational artifacts (mach banding, etc) so G'MIC performs all computations in 32 bit floating point. For that reason alone, you should probably work in that environment, because sadly, much of Gimp is still 8 bit, unsigned integer, so chunks of the pipeline lack the numerical precision you (should) prefer. That will change, and hopefully Real Soon Now, but probably not in the next day or two.

Well, in the time that I've written this, your file still hasn't downloaded, so I'm going to have to punt. I'm assuming in colorwheel terms, the transformation you are looking for is something like this:
Untransformed colorwheel -
[ Image ]
Blue isolation, translation to grayscale:
[ Image ]

The G'MIC filter that rendered this particular transformation looks like this:
#@gimp Blue Filter: blufilter
#@gimp : txt = text("Documentation? You want documentation? HA!!!")
#@gimp : sep = separator()
blufilter :
-e[^-1] "Isolate Blue components via LAB/RGB space modification."
-verbose -
-repeat @#
   -local[$>]
      -rgb2lab[-1]
      -split c
      -fill_color[-2] 0,0,0
      -normalize[-1] -127,127
      -append[-3--1] c
      -lab2rgb[-1]
      -channels[-1] 2
      -luminance[-1]
    -endlocal
-done
-verbose +

This is little more than a translation of your process in G'MIC speak; my temptaton is to rewrite it around -select_color, so that you could specify any number of keep-supress hues. And, in the G'MIC-Gimp plug-in there is an interactive LAB filter based on setting curve profiles, as in the Gimp curve tool, so you need not script anything at all, but for now I think best to keep the solution near to the form as you stated it.

So what to do with this? Assuming you have a basic Gimp, you need to install G'MIC. The simplest way is probably to go over to Partha's Place and fetch a fresh Gimp for your platform; he has pre-installed G'MIC for you. The Official method is to go over to gmic.soureforge.net and fetch the gmic_gimp binary and drop it into your plugin folder. Platform specific instructions may be found on the download page, scroll down a bit until you see the typewriter text copy.
With G'MIC in place, the little code snippet above will go into your personal .gmic folder ($HOME/.gmic on Linux/Mac/Unix-like) or %APPDATA%/gmic (Windows), the repository for your personal G'MIC commands. Upon plugin restart (or upon starting Gimp) you should have G'MIC as the last item on your Gimp filters menu and something called "Blue Filter" Blue filter has no controls, it will work on the current active layer in preview, and transform the current layer upon "Apply/OK"
For lots and lots of files (did you say hundreds?) I would suggest (strongly) fetching the "gmic" binary from gmic.sourceforge.net. That is a stand-alone, command-line oriented interpreter of the G'MIC scripting language. It has its own looping constructs, or, if your more comfortable with shell/Perl/Python scripting, you could call the gmic interpreter as a subprocess.

That's the basics from the G'MIC front. As noted in the outset, there are many ways to skin this. G'MIC gives you a 32-bit floating point pipeline for a minimum of artifacts arising from numeric precision.

Garry


GMIC also works as an independent command-line utility, which would be more apprpriate in this case.

_________________
Image


Top
Post new topic Reply to topic  [ 13 posts ] 

All times are UTC - 5 hours [ DST ]


   Similar Topics   Replies 
No new posts Attachment(s) Disintegration of objects in a layer

4

No new posts Attachment(s) removing px from the bottom of a image

4

No new posts Removing text from a poster imported as an image

3

No new posts Attachment(s) Path: reduce the number of nodes while keeping the shape

9

No new posts Attachment(s) Removing flare

2



* Login  



Powered by phpBB3 © phpBB Group