简体   繁体   中英

scale image with marvin

I am using the Marvin Image Processing Framework in Java and I am struggling to scale the image. It's just making a black square, can you see what I have done wrong? The set threshold is working.

package com.example.marvin;

import marvin.image.MarvinImage;
import marvin.io.MarvinImageIO;
import marvin.plugin.MarvinImagePlugin;
import marvin.util.MarvinPluginLoader;

public class Imageprocess {

    public static void main (String[] args) {

        MarvinImage image = MarvinImageIO
                .loadImage("/Users/unknown1/Desktop/images.jpeg");

        MarvinImagePlugin thresholdplugin = MarvinPluginLoader
                .loadImagePlugin("org.marvinproject.image.color.thresholding.jar");

        MarvinImagePlugin scaleplugin = MarvinPluginLoader
                .loadImagePlugin("org.marvinproject.image.transform.scale.jar");

        thresholdplugin.setAttribute("threshold", 85);
        thresholdplugin.process(image, image);


        scaleplugin.setAttribute("newWidth", 50);
        scaleplugin.setAttribute("newHeight", 37);
        scaleplugin.process(image, image);

        image.update();

        MarvinImageIO.saveImage(image, "/Users/unknown1/Desktop/images1.jpeg");
    }

}

It works using the latest version of Marvin!

import marvin.image.MarvinImage;
import marvin.io.MarvinImageIO;

import static marvin.MarvinPluginCollection.*;

public class Imageprocess {

    public static void main (String[] args) {
        MarvinImage image = MarvinImageIO.loadImage("./res/chamaleon.jpg");
        thresholding(image, 85);
        scale(image.clone(), image, 50, 37);
        MarvinImageIO.saveImage(image, "./res/chamaleon_scaled.jpg");
    }
}

you need to do image.update(); after each process

and then you get the following code:

    ...
    thresholdplugin.setAttribute("threshold", 85);
    thresholdplugin.process(image, image);

    image.update();

    scaleplugin.setAttribute("newWidth", 50);
    scaleplugin.setAttribute("newHeight", 37);
    scaleplugin.process(image, image);

    image.update();
    ...

and of course, it's better to use the latest version of the plugin

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM