Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #29076 > unrolled thread
| Started by | jf498989@gmail.com |
|---|---|
| First post | 2014-07-12 13:49 -0700 |
| Last post | 2014-07-19 08:18 -0400 |
| Articles | 8 — 5 participants |
Back to article view | Back to comp.lang.java.programmer
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: Sepia tone image filter for Java jf498989@gmail.com - 2014-07-12 13:49 -0700
Re: Sepia tone image filter for Java Roedy Green <see_website@mindprod.com.invalid> - 2014-07-14 02:12 -0700
Re: Sepia tone image filter for Java Joerg Meier <joergmmeier@arcor.de> - 2014-07-14 11:24 +0200
Re: Sepia tone image filter for Java Roedy Green <see_website@mindprod.com.invalid> - 2014-07-15 03:59 -0700
Re: Sepia tone image filter for Java Knute Johnson <eternal@knutejohnson.com> - 2014-07-15 10:11 -0700
Re: Sepia tone image filter for Java Knute Johnson <eternal@knutejohnson.com> - 2014-07-15 10:22 -0700
Re: Sepia tone image filter for Java Knute Johnson <eternal@knutejohnson.com> - 2014-07-17 18:53 -0700
Re: Sepia tone image filter for Java Jeff Higgins <jeff@invalid.invalid> - 2014-07-19 08:18 -0400
| From | jf498989@gmail.com |
|---|---|
| Date | 2014-07-12 13:49 -0700 |
| Subject | Re: Sepia tone image filter for Java |
| Message-ID | <ae206f7a-9d4b-44f2-9577-1def95831b53@googlegroups.com> |
On Monday, June 29, 2009 11:03:09 PM UTC-7, Macky G wrote:
> After spending hours searching the web and not finding an answer, I
> finally put together a function to create sepia images with Java.
> This function produces amazing results, I'm very happy with it. I
> hope it saves everyone time...
>
> (You'll need your image to be in a BufferedImage object. The web has
> plenty of tutorials for that.)
>
>
> /**
> *
> * @param img Image to modify
> * @param sepiaIntensity From 0-255, 30 produces nice results
> * @throws Exception
> */
> public static void applySepiaFilter(BufferedImage img, int
> sepiaIntensity) throws Exception
> {
> // Play around with this. 20 works well and was recommended
> // by another developer. 0 produces black/white image
> int sepiaDepth = 20;
>
> int w = img.getWidth();
> int h = img.getHeight();
>
> WritableRaster raster = img.getRaster();
>
> // We need 3 integers (for R,G,B color values) per pixel.
> int[] pixels = new int[w*h*3];
> raster.getPixels(0, 0, w, h, pixels);
>
> // Process 3 ints at a time for each pixel. Each pixel has 3 RGB
> colors in array
> for (int i=0;i<pixels.length; i+=3)
> {
> int r = pixels[i];
> int g = pixels[i+1];
> int b = pixels[i+2];
>
> int gry = (r + g + b) / 3;
> r = g = b = gry;
> r = r + (sepiaDepth * 2);
> g = g + sepiaDepth;
>
> if (r>255) r=255;
> if (g>255) g=255;
> if (b>255) b=255;
>
> // Darken blue color to increase sepia effect
> b-= sepiaIntensity;
>
> // normalize if out of bounds
> if (b<0) b=0;
> if (b>255) b=255;
>
> pixels[i] = r;
> pixels[i+1]= g;
> pixels[i+2] = b;
> }
> raster.setPixels(0, 0, w, h, pixels);
> }
Hi: this code works super good. I have converted it to BBC Bacic for Windows. what is your full name as I like to pass on credit to my group where due.
Thank you John Fortier
[toc] | [next] | [standalone]
| From | Roedy Green <see_website@mindprod.com.invalid> |
|---|---|
| Date | 2014-07-14 02:12 -0700 |
| Message-ID | <ln77s9lrnc8anip3l5na1juuqc6ru3j71g@4ax.com> |
| In reply to | #29076 |
On Sat, 12 Jul 2014 13:49:16 -0700 (PDT), jf498989@gmail.com wrote, quoted or indirectly quoted someone who said : > // Darken blue color to increase sepia effect Hmm. I thought sepia added a brown tone, e.g. more yellow and red. -- Roedy Green Canadian Mind Products http://mindprod.com A program is only as good as its worst piece of code. ~ Joshua Cramer
[toc] | [prev] | [next] | [standalone]
| From | Joerg Meier <joergmmeier@arcor.de> |
|---|---|
| Date | 2014-07-14 11:24 +0200 |
| Message-ID | <9qcxpjcscbfw$.mnsqslm70xg3.dlg@40tude.net> |
| In reply to | #29092 |
On Mon, 14 Jul 2014 02:12:48 -0700, Roedy Green wrote: > On Sat, 12 Jul 2014 13:49:16 -0700 (PDT), jf498989@gmail.com wrote, > quoted or indirectly quoted someone who said : >> // Darken blue color to increase sepia effect > Hmm. I thought sepia added a brown tone, e.g. more yellow and red. Yes, that is typically what happens when you darken blue. On a computer screen, "darken" means less of a colour ;) Liebe Gruesse, Joerg -- Ich lese meine Emails nicht, replies to Email bleiben also leider ungelesen.
[toc] | [prev] | [next] | [standalone]
| From | Roedy Green <see_website@mindprod.com.invalid> |
|---|---|
| Date | 2014-07-15 03:59 -0700 |
| Message-ID | <r92as9lggp23l68v4ag7o6bkiibdvqcg80@4ax.com> |
| In reply to | #29093 |
On Mon, 14 Jul 2014 11:24:10 +0200, Joerg Meier <joergmmeier@arcor.de> wrote, quoted or indirectly quoted someone who said : >Yes, that is typically what happens when you darken blue. On a computer >screen, "darken" means less of a colour ;) Of course. I was thinking in terms of paint, where adding more blue paint would be "darkening" the blue. -- Roedy Green Canadian Mind Products http://mindprod.com Science is what we understand well enough to explain to a computer. Art is everything else we do. ~ Donald Ervin Knuth (born: 1938-01-10 age: 76)
[toc] | [prev] | [next] | [standalone]
| From | Knute Johnson <eternal@knutejohnson.com> |
|---|---|
| Date | 2014-07-15 10:11 -0700 |
| Message-ID | <lq3nbd$d96$1@dont-email.me> |
| In reply to | #29107 |
On 7/15/2014 03:59, Roedy Green wrote:
> On Mon, 14 Jul 2014 11:24:10 +0200, Joerg Meier <joergmmeier@arcor.de>
> wrote, quoted or indirectly quoted someone who said :
>
>> Yes, that is typically what happens when you darken blue. On a computer
>> screen, "darken" means less of a colour ;)
>
> Of course. I was thinking in terms of paint, where adding more blue
> paint would be "darkening" the blue.
>
A sepia tone filter is trickier than I thought. I need to compare the
results from this code with the sepia filter in JavaFX.
import java.awt.*;
import java.awt.color.*;
import java.awt.image.*;
import java.net.*;
import javax.imageio.*;
import javax.swing.*;
public class test0 extends JPanel {
private BufferedImage orig,sepia;
public test0() {
try {
URL url = new URL(
"http://rabbitbrush.frazmtn.com/xlsjacksonhole.jpg");
orig = ImageIO.read(url);
setPreferredSize(new
Dimension(orig.getWidth(),orig.getHeight()*2));
// convert to grayscale and back to RGB
ColorSpace imgCS = orig.getColorModel().getColorSpace();
ColorSpace grayCS = ColorSpace.getInstance(ColorSpace.CS_GRAY);
ColorConvertOp cop = new ColorConvertOp(imgCS,grayCS,null);
sepia = cop.filter(orig,null);
cop = new ColorConvertOp(grayCS,imgCS,null);
sepia = cop.filter(sepia,null);
// slightly enhance the red, slightly reduce the green and
// remove half the blue
float[] factor = new float[] { 1.1f,.9f,.5f };
float[] offset = new float[] { 0f,0f,0f };
RescaleOp rop = new RescaleOp(factor,offset,null);
sepia = rop.filter(sepia,null);
} catch (Exception e) {
e.printStackTrace();
}
}
public void paintComponent(Graphics g2d) {
g2d.drawImage(orig,0,0,null);
g2d.drawImage(sepia,0,sepia.getHeight(),null);
}
public static void main(String... args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
JFrame f = new JFrame("test0");
f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
f.add(new test0(),BorderLayout.CENTER);
f.pack();
f.setVisible(true);
}
});
}
}
--
Knute Johnson
[toc] | [prev] | [next] | [standalone]
| From | Knute Johnson <eternal@knutejohnson.com> |
|---|---|
| Date | 2014-07-15 10:22 -0700 |
| Message-ID | <lq3nvn$hpl$1@dont-email.me> |
| In reply to | #29110 |
I like these scale factors even better
float[] factor = new float[] { 1.35f,1f,.7f };
On 7/15/2014 10:11, Knute Johnson wrote:
> On 7/15/2014 03:59, Roedy Green wrote:
>> On Mon, 14 Jul 2014 11:24:10 +0200, Joerg Meier <joergmmeier@arcor.de>
>> wrote, quoted or indirectly quoted someone who said :
>>
>>> Yes, that is typically what happens when you darken blue. On a computer
>>> screen, "darken" means less of a colour ;)
>>
>> Of course. I was thinking in terms of paint, where adding more blue
>> paint would be "darkening" the blue.
>>
>
> A sepia tone filter is trickier than I thought. I need to compare the
> results from this code with the sepia filter in JavaFX.
>
> import java.awt.*;
> import java.awt.color.*;
> import java.awt.image.*;
> import java.net.*;
> import javax.imageio.*;
> import javax.swing.*;
>
> public class test0 extends JPanel {
> private BufferedImage orig,sepia;
>
> public test0() {
> try {
> URL url = new URL(
> "http://rabbitbrush.frazmtn.com/xlsjacksonhole.jpg");
> orig = ImageIO.read(url);
> setPreferredSize(new
> Dimension(orig.getWidth(),orig.getHeight()*2));
>
> // convert to grayscale and back to RGB
> ColorSpace imgCS = orig.getColorModel().getColorSpace();
> ColorSpace grayCS =
> ColorSpace.getInstance(ColorSpace.CS_GRAY);
> ColorConvertOp cop = new ColorConvertOp(imgCS,grayCS,null);
> sepia = cop.filter(orig,null);
> cop = new ColorConvertOp(grayCS,imgCS,null);
> sepia = cop.filter(sepia,null);
>
> // slightly enhance the red, slightly reduce the green and
> // remove half the blue
> float[] factor = new float[] { 1.1f,.9f,.5f };
> float[] offset = new float[] { 0f,0f,0f };
> RescaleOp rop = new RescaleOp(factor,offset,null);
> sepia = rop.filter(sepia,null);
> } catch (Exception e) {
> e.printStackTrace();
> }
> }
>
> public void paintComponent(Graphics g2d) {
> g2d.drawImage(orig,0,0,null);
> g2d.drawImage(sepia,0,sepia.getHeight(),null);
> }
>
> public static void main(String... args) {
> EventQueue.invokeLater(new Runnable() {
> public void run() {
> JFrame f = new JFrame("test0");
> f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
> f.add(new test0(),BorderLayout.CENTER);
> f.pack();
> f.setVisible(true);
> }
> });
> }
> }
>
>
--
Knute Johnson
[toc] | [prev] | [next] | [standalone]
| From | Knute Johnson <eternal@knutejohnson.com> |
|---|---|
| Date | 2014-07-17 18:53 -0700 |
| Message-ID | <lq9ume$8hl$1@dont-email.me> |
| In reply to | #29111 |
On 7/17/2014 18:34, Stefan Ram wrote:
> Knute Johnson <eternal@knutejohnson.com> writes:
>> I like these scale factors even better
>> float[] factor = new float[] { 1.35f,1f,.7f };
>
> docs.oracle.com/javafx/2/api/javafx/scene/effect/SepiaTone.html
>
Thanks
--
Knute Johnson
[toc] | [prev] | [next] | [standalone]
| From | Jeff Higgins <jeff@invalid.invalid> |
|---|---|
| Date | 2014-07-19 08:18 -0400 |
| Message-ID | <lqdo5g$n9d$1@dont-email.me> |
| In reply to | #29111 |
On 07/15/2014 01:22 PM, Knute Johnson wrote:
> I like these scale factors even better
>
> float[] factor = new float[] { 1.35f,1f,.7f };
"Digital Black and White Conversion | Photoshop"
<http://landscapephoto.us/Articles/DigitalBlackAndWhite.html>
especially "For Further Reading" and beyond.
Seems that the toning process is the easy part.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.java.programmer
csiph-web