<jupyter_start><jupyter_text>Mixed World: Using ImageJ 1.xFamiliar with [ImageJ 1.x](https://imagej.net/ImageJ1)? Want to mix and match? Here's how.  Enabling ImageJ 1.x In order to make use of [ImageJ 1.x](https://imagej.net/ImageJ1) functionality, we need to ensure the [ImageJ Legacy](https://imagej.net/ImageJ_Legacy) component is present on the runtime classpath.<jupyter_code>#@ImageJ ij

// Behind a firewall? Configure your proxy settings here.
//System.setProperty("http.proxyHost","myproxy.domain")
//System.setProperty("http.proxyPort","8080")

"ImageJ is ready to go."<jupyter_output><empty_output><jupyter_text>ImageJ2 patches ImageJ 1.x so that it can run [headless](https://imagej.net/Headless). However, the SciJava Jupyter kernel does _not_ launch Java headless by default.Let's check whether we are running headless now:<jupyter_code>[["Running headless?": Boolean.getBoolean("java.awt.headless"),
"Does ImageJ agree?": ij.ui().isHeadless(),
"GraphicsEnvironment?": java.awt.GraphicsEnvironment.isHeadless()]]<jupyter_output><empty_output><jupyter_text>Calling ImageJ 1.x directly Either way, we can call the ImageJ1 API directly as desired:<jupyter_code>import ij.IJ
blobsIJ1 = IJ.openImage("http://imagej.net/images/blobs.gif")<jupyter_output><empty_output><jupyter_text>Using the legacy service The ImageJ Legacy component includes a handy `LegacyService` which provides operations bridging the gap between ImageJ 1.x and ImageJ2. For example, we can convert an ImageJ2 `Dataset` to an ImageJ1 `ImagePlus`:<jupyter_code>#@LegacyService legacy

// Open an IJ2 Dataset.
clown = ij.io().open("http://imagej.net/images/clown.png")

// Convert it to an IJ1 ImagePlus.
clownDisplay = ij.display().createDisplay(clown)
clownIJ1 = legacy.getImageMap().registerDisplay(clownDisplay)

[["IJ2 clown":clown, "IJ1 clown":clownIJ1]]<jupyter_output><empty_output><jupyter_text>And ImageJ1 `ImagePlus` objects can be converted to ImageJ2 `ImageDisplay` and/or `Dataset`:<jupyter_code>// Convert IJ1 blobs image to an IJ2 image.
blobsDisplay = legacy.getImageMap().registerLegacyImage(blobsIJ1)
blobsIJ2 = blobsDisplay.get(0).getData()

[["IJ1 blobs":blobsIJ1, "IJ2 blobs":blobsIJ2]]<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12404149751917005, 'fraction_numerical': 0.016238159675236806, 'mean_word_length': 6.621993127147766, 'pattern_counts': {'":': 7, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '300742', 'license': 'CC0-1.0', 'n_tokens_mistral': 781, 'n_tokens_neox': 744, 'n_words': 192, 'path': 'notebooks/1_-_Using_ImageJ/5_-_Mixed_World_-_Using_ImageJ_1.x.ipynb', 'repo_name': 'fjug/tutorials', 'size': '2217'}