Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #15617
| Path | csiph.com!usenet.pasdenom.info!gegeweb.org!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | Knute Johnson <nospam@knutejohnson.com> |
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: Image Thinning using JAVA |
| Date | Tue, 26 Jun 2012 14:26:45 -0700 |
| Organization | A noiseless patient Spider |
| Lines | 67 |
| Message-ID | <jsd9em$hur$1@dont-email.me> (permalink) |
| References | <csqdnUsK6PaldXTSnZ2dnUVZ_vednZ2d@giganews.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=ISO-8859-1; format=flowed |
| Content-Transfer-Encoding | 7bit |
| Injection-Date | Tue, 26 Jun 2012 21:26:46 +0000 (UTC) |
| Injection-Info | mx04.eternal-september.org; posting-host="mz/LDSJwiWnk3Jnnqg7x+Q"; logging-data="18395"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19mlK0lK3Yn72PiS+Ivj5Iq" |
| User-Agent | Mozilla/5.0 (Windows NT 5.1; rv:13.0) Gecko/20120614 Thunderbird/13.0.1 |
| In-Reply-To | <csqdnUsK6PaldXTSnZ2dnUVZ_vednZ2d@giganews.com> |
| Cancel-Lock | sha1:rDhkXPC9FCBtfcz1jNShGjhWCqI= |
| Xref | csiph.com comp.lang.java.programmer:15617 |
Show key headers only | View raw
On 6/26/2012 9:50 AM, sumera wrote:
> Hi!
> I have written some code in java to convert a colored image into black and white image and then tried to perform thinning on that gray-scale image. Black and white conversion is done successfully, but image thinning is still not giving correct output. Kindly help me in fixing my problem. My code is as follows:
>
> //colored image to black and white conversion; black and white image to thinned image.
>
> public static void main(String[] args)
> {
> try
> {
> //colored image path
> BufferedImage colored_image = ImageIO.read(new File("D:\\logo.jpg"));
> //getting width and height of image
> double image_width = colored_image.getWidth();
> double image_height = colored_image.getHeight();
> BufferedImage img = colored_image;
>
> //drawing a new image
> BufferedImage bimg = new BufferedImage((int)image_width, (int)image_height, BufferedImage.TYPE_BYTE_GRAY);
> Graphics2D gg = bimg.createGraphics();
> gg.drawImage(img, 0, 0, img.getWidth(null), img.getHeight(null), null);
>
> //saving black and white image onto drive
> String temp = "logo in blackAndwhite.jpeg";
> File fi = new File("D:\\" + temp);
> ImageIO.write(bimg, "jpg", fi);
>
> //thinning by resizing gray scale image to desired eight and width
> BufferedImage bimg2 = new BufferedImage((int)image_width, (int)image_height, BufferedImage.TYPE_INT_ARGB);
> Graphics2D g2 = bimg2.createGraphics();
>
> // Perform your drawing here
> g2.setColor(Color.BLACK);
> g2.drawLine(0, 0, 200, 200);
>
> //saving thinned image onto drive
> String temp2 = "logo thinned.jpeg";
> File fi2 = new File("D:\\" + temp2);
> ImageIO.write(bimg2, "jpg", fi2);
> //g2.dispose();
> }
> catch (Exception e)
> {
> System.out.println(e);
> }
> }
>
>
public static BufferedImage convertToGray(BufferedImage image) {
BufferedImage gray = new BufferedImage(image.getWidth(),
image.getHeight(),BufferedImage.TYPE_BYTE_GRAY);
ColorConvertOp op = new ColorConvertOp(
image.getColorModel().getColorSpace(),
gray.getColorModel().getColorSpace(),null);
op.filter(image,gray);
return gray;
}
You can use the same technique as above with an AffineTransformOp, as
John Matthews mentioned, to scale an image.
--
Knute Johnson
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Image Thinning using JAVA sumera <kanwal.sumera@yahoo.com> - 2012-06-26 11:50 -0500
Re: Image Thinning using JAVA markspace <-@.> - 2012-06-26 10:21 -0700
Re: Image Thinning using JAVA "John B. Matthews" <nospam@nospam.invalid> - 2012-06-26 14:39 -0400
Re: Image Thinning using JAVA Knute Johnson <nospam@knutejohnson.com> - 2012-06-26 14:26 -0700
Re: Image Thinning using JAVA "John B. Matthews" <nospam@nospam.invalid> - 2012-06-26 23:15 -0400
Re: Image Thinning using JAVA Knute Johnson <nospam@knutejohnson.com> - 2012-06-26 22:04 -0700
Re: Image Thinning using JAVA "John B. Matthews" <nospam@nospam.invalid> - 2012-06-27 21:35 -0400
Re: Image Thinning using JAVA Roedy Green <see_website@mindprod.com.invalid> - 2012-06-27 07:01 -0700
csiph-web