Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8329795
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T01:54:47+00:00 2026-06-09T01:54:47+00:00

Is there a way to implement Duotone effect in Java? A good example of

  • 0

Is there a way to implement “Duotone” effect in Java?

A good example of what I’d like to do is here or here

I guess BandCombineOp might help.
To me I should convert it to grays first and then apply smth like threshold effect.
But I didn’t manage to achieve good output.

Also I don’t understand how can I set up colors for this effect.

float[][] grayMatrix = new float[][]
            {
               new float[] {0.3f, 0.3f, 0.3f},
               new float[] {0.3f, 0.3f, 0.3f},
               new float[] {0.3f, 0.3f, 0.3f},
            };

    float[][] duoToneMatrix = new float[][]
            {
                    new float[] {0.1f, 0.1f, 0.1f},
                    new float[] {0.2f, 0.2f, 0.2f},
                    new float[] {0.1f, 0.1f, 0.1f},
            };

    BufferedImage src = ImageIO.read(new File("X:\\photoshop_image_effects.jpg"));
    WritableRaster srcRaster = src.getRaster();

    // make it gray
    BandCombineOp bco = new BandCombineOp(grayMatrix, null);
    WritableRaster dstRaster = bco.createCompatibleDestRaster(srcRaster);
    bco.filter(srcRaster, dstRaster);

    // apply duotone
    BandCombineOp duoToneBco = new BandCombineOp(duoToneMatrix, null);
    WritableRaster dstRaster2 = bco.createCompatibleDestRaster(dstRaster);
    duoToneBco.filter(dstRaster, dstRaster2);

    BufferedImage result = new BufferedImage(src.getColorModel(), dstRaster2, src.getColorModel().isAlphaPremultiplied(), null);
    ImageIO.write(result, "png", new File("X:\\result_duotone.png"));

My output enter image description here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T01:54:48+00:00Added an answer on June 9, 2026 at 1:54 am

    From what I can tell you are trying to change the colouring of an image without changing its luminosity. Note the difference from luminance.

    Regardless of whether you are aiming for luminance or luminosity, your problem boils down to varying the relative contributions of B, G, and R without changing their weighted sum. Your first matrix converts to greyscale by setting B,G,R to the same value and only slightly changing their luminance (.3+.3+.3 = .9). To use luminosity instead use

    greyMatrix = (.11,.59,.3,
                  .11,.59,.3,
                  .11,.59,.3); //note this is for bgr
    

    Then you want to change their relative weighting without changing their weighted sum. First, note that since after greyscale conversion your B,G,R values are the same you could replace your matrix with

    duoToneMatrix = (0,.3,0,
                     0,.6,0,
                     0,.3,0,)
    

    and it would be equivalent. To conserve luminance you need to choose 3 factors such that their sum is 1. Those three factors can be applied in the duoTone Matrix. The larger a factor is, the more tinted the image will be with that colour. To preserve luminosity you need 3 factors fb,fg,fr such that

    fb*.11+fg*.59+fr*.3 = 1; //again for bgr
    

    You can choose your factors fb, fg, fr to find the tint of your choosing.

    Also, note that you can do this with one matrix. Just combine the two matrices you already have.

    [duoToneMatrix]*[greyMatrix]*vector = ([duoToneMatrix]*[greyMatrix])*vector;
    

    just compute the product of duoToneMatrix and greyMatrix (in that order) and process in one step.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any way to implement a Google feedback like feature as shown here
Is there a way to implement using eigen something like (pseudocode): A = BooleanExpr(X)
Is there a way to implement functionality like Class Categories (of Objective-C) or Extension
Is there some way to implement Django like contains or icontains filters with Google
Is there a way to implement something like COMMIT transactions of RDBMSs in R
Is there a way to implement pagination like Googles show more results with jQuery
Is there any way to implement row span and colspan in JTable like html
Is there standard way to implement standard Iphone Check List like when you choose
Is there any way to implement a URL mechanisim in asp.net like it has
Is there a way to implement PostScript like page display for text files in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.