<commit_before>package be.cytomine.processing

import be.cytomine.processing.image.filters.Colour_Deconvolution
import be.cytomine.processing.merge.CytomineRGBStackMerge
import http.HttpClient
import ij.ImagePlus
import ij.plugin.ContrastEnhancer
import ij.process.ImageConverter

import javax.imageio.ImageIO
import java.awt.*
import java.awt.image.BufferedImage

/**
 * Cytomine @ GIGA-ULG
 * User: stevben
 * Date: 1/06/11
 * Time: 13:44
 */
class VisionController {

    def imageProcessingService


    def merge () {

        def urls = params.url.split(',')
        def colors = params.url.split('color')
        colors = colors.collect{
            int intValue = Integer.parseInt(it,16);
            return new Color( intValue );
        }

        def zoomifyParam = params.get('zoomify')

        log.info "Urls=$urls"
        log.info "Colors=$colors"

        if(!urls.isEmpty()) {

            log.info "urls=$urls"

            ImagePlus[] images = new ImagePlus[urls.size()]


            urls.eachWithIndex { url, index ->
                log.info "load=${url+zoomifyParam}"
                images[index] = new ImagePlus("Image$index",(java.awt.Image)ImageIO.read(new URL(url+zoomifyParam)))
            }

            Color[] colorsArray = colors.toArray(new Color[colors.size()])
            ImagePlus result = CytomineRGBStackMerge.merge(images,colorsArray,false)

            BufferedImage resultImage = result.getBufferedImage()

            responseBufferedImage(resultImage)

        } else {
            render "url arugment is missing (start with url0=)!"
            response.status = 400
        }
    }

    /**
     * Read a picture from url
     * @param url Picture url
     * @return Picture as an object
     */
    protected BufferedImage getImageFromURL(String url) {
        def out = new ByteArrayOutputStream()<commit_msg>recover url & color parsing method for merge method<commit_after>package be.cytomine.processing

import be.cytomine.processing.image.filters.Colour_Deconvolution
import be.cytomine.processing.merge.CytomineRGBStackMerge
import http.HttpClient
import ij.ImagePlus
import ij.plugin.ContrastEnhancer
import ij.process.ImageConverter

import javax.imageio.ImageIO
import java.awt.*
import java.awt.image.BufferedImage

/**
 * Cytomine @ GIGA-ULG
 * User: stevben
 * Date: 1/06/11
 * Time: 13:44
 */
class VisionController {

    def imageProcessingService


    def merge () {

        def urls = extractParams("url")
        def colors = extractParams("color")
        colors = colors.collect{
            int intValue = Integer.parseInt(it,16);
            return new Color( intValue );
        }

        def zoomifyParam = params.get('zoomify')

        log.info "Urls=$urls"
        log.info "Colors=$colors"

        if(!urls.isEmpty()) {

            log.info "urls=$urls"

            ImagePlus[] images = new ImagePlus[urls.size()]


            urls.eachWithIndex { url, index ->
                log.info "load=${url+zoomifyParam}"
                images[index] = new ImagePlus("Image$index",(java.awt.Image)ImageIO.read(new URL(url+zoomifyParam)))
            }

            Color[] colorsArray = colors.toArray(new Color[colors.size()])
            ImagePlus result = CytomineRGBStackMerge.merge(images,colorsArray,false)

            BufferedImage resultImage = result.getBufferedImage()

            responseBufferedImage(resultImage)

        } else {
            render "url arugment is missing (start with url0=)!"
            response.status = 400
        }
    }

    /**
     * Extract all args into a list.
     * argStart0, argStart1, argStart2... => [argStart0,argStart1...]
     * @param argStart
     */
    private def extractParams(String argStart) {
        def list = []
        int i=0;
        String nextUrlParams = params.get(argStart+i)
        log.info "nextUrlParams=" +nextUrlParams

        while(nextUrlParams!=null) {
            log.info "nextUrlParams=$nextUrlParams"
            list << nextUrlParams
            i++
            nextUrlParams = params.get(argStart+i)
        }
        return list
    }

    /**
     * Read a picture from url
     * @param url Picture url
     * @return Picture as an object
     */
    protected BufferedImage getImageFromURL(String url) {
        def out = new ByteArrayOutputStream()
{'fraction_non_alphanumeric': 0.10460541541309883, 'fraction_numerical': 0.00833140476741495, 'mean_word_length': 2.384494909945184, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 6, 'https://': 0, '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}}
{'dir': 'git-commits-cleaned', 'id': '5832607', 'n_tokens_mistral': 1293, 'n_tokens_neox': 1241, 'n_words': 274}