3

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");
    }

}
Gabriel Archanjo
  • 4,547
  • 2
  • 34
  • 41
volican
  • 137
  • 1
  • 14

2 Answers2

1

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");
    }
}
Gabriel Archanjo
  • 4,547
  • 2
  • 34
  • 41
1

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

Sergey Zh.
  • 347
  • 2
  • 3
  • 13
  • 1
    Hey @SergeyZh, welcome to SO. While we really do welcome newer answers to old questions, as a new contributor I thought you should probably be prompted to check the dates on the questions you answer, just to check that you had noticed that this question is 6-years old. – Software Engineer May 16 '21 at 21:51