Login  Register

Histogram Matching | python script attached, questions remain

Posted by Rainer M. Engel on Oct 08, 2019; 11:40am
URL: http://imagej.273.s1.nabble.com/Histogram-Matching-python-script-attached-questions-remain-tp5022497.html

Hey everyone..

I'm typically working with another software, where histogram matching is
easy available. Recently I stumbled upon an thread on stack overflow on
this topic with ImageJ
https://stackoverflow.com/questions/25085871/match-histogram-imagej

Since I wanted to create a "script plugin" which I can call from a
macro, I finally chose python, because it was easier to find examples
helping me out.

I used these two images..
"https://juliahartel.files.wordpress.com/2013/07/kornfeld-in-goldener-abendsonne.jpg"
"https://naturfotografen-forum.de/data/o/142/713934/image::Frank_Steinmann_auwald_rheinaue_wald.jpg"

Hoping the indentation is preserved!
#PYTHON-CODE---------------------------------------------------
from fiji.util.gui import GenericDialogPlus
import ij.IJ
from histogram2 import HistogramMatcher


# Create an instance of GenericDialogPlus
gui = GenericDialogPlus("histogram matching..")

# Add possibility to choose some images already opened in Fiji
gui.addImageChoice("target image","image1")
gui.addImageChoice("reference image","image2")

gui.showDialog()

# Recover the inputs in order of "appearance"
if gui.wasOKed():
    ImpImage1 = gui.getNextImage() # This method directly returns the
ImagePlus object
    ImpImage2 = gui.getNextImage()

ip1 = ImpImage1.getProcessor()
ip2 = ImpImage2.getProcessor()

hist1 = ip1.getHistogram()
hist2 = ip2.getHistogram()

matcher = HistogramMatcher()
newHist = matcher.matchHistograms(hist1, hist2)

ip1.applyTable(newHist)
ImpImage1.setProcessor(ip1)

ImpImage1.show()
ImpImage2.show()
#PYTHON-CODE---------------------------------------------------


Questions:
1) This works interactively, but on first execution I get an error:
[INFO] Reading available sites from https://imagej.net/
console: Failed to install '':
java.nio.charset.UnsupportedCharsetException: cp0.
What can I do about this char-error?


2) I hoped calling it from a macro would work with ease.. but I do not
know how or where to put the script.

run("script:histogram-match.py", "target=[image
Frank_Steinmann_auwald_rheinaue_wald.jpg]
reference=kornfeld-in-goldener-abendsonne.jpg");

With the above, I get an file.io error.

<Error: java.io.FileNotFoundException:
http://wsr.imagej.net/download/Examples/Python/script:G:ImageJ_hist-matchhistogram-match.py>
in line 1:
        var ; initializeSciJavaParameters ( ) ; run (
"script:G:ImageJ_hist-matchhistogram-match.py" , "target=[image Frank_Ste...


3) Can someone point me to python examples of a script, which
differentiates between image types? What the provided script needs is a
fork for RGB images (Split Channels, working on them separately and
merging them later on again). This creates very good results. One would
only need to tiny smooth the correction curve, to reduce artefacts
(especially if i.e. "kornfeld" is the target image). Currently I don't
know if this is possible with "histogram2".


Thank you very much, for any direction or help..

Kind regards,
Rainer

--
Rainer M. Engel

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html