Improvement is needed for structure image

User d68ef9d5a9

21-12-2005 15:58:59

Hi,





I am try to directly use the image of a molecule for web or non-web applications. But I found the black & white image is not sharp enough. The black bonds are not totally black and they are even blurer when the image size is reduced. I wonder if there is any easy way to make to bonds complete black, and, if possible, the color of the bonds will not change when the image size is reduced.





Regards,





Ben Li


Neurogen Corporation

User d68ef9d5a9

21-12-2005 17:12:28

I like to clarify a bit more about my question. I am using wireframe in the image. I also see option to increase bond thickness in Marvin View. How can I increase the bond thickness in Java programming? e.g.





byte[] d5 = mol.toBinFormat("jpeg:w300,h300,#ffffff,wireframe");





Thanks.





Ben Li

ChemAxon 7c2d26e5cf

22-12-2005 14:14:27

In the current Marvin, there is no option in the Molecule.toBinFormat() method for the bond thickness. You can set the bond thickness in MSketchPane or in MViewPane:


http://www.chemaxon.com/marvin/doc/api/chemaxon/marvin/beans/MarvinPane.html#setWireThickness(double)


Until we implement this image export option in the toBinFormat() method, I suggest you the following workaround:


Create an unvisible sketch panel then set its layout options and get the image from the editor.
Quote:



// create a sketcher and put it into a frame


JFrame frame = new JFrame();


MSketchPane sketchpanel = MSketchPane();


frame.getContentPane().add(sketchpanel);





// set the layout for image export


sketchpanel.setRendering("wireframe");


sketchpanel.setMolbg(new Color(0xffffff));


sketchpanel.setWireThickness(0.084);


sketchpanel.setMol(mol);





// arange components inside the frame but do not display it


frame.pack();





// get the image


java.awt.Image img = sketchpanel.getImage(new Dimension(300,300));





// convert Image into an OutputStream to be able to save it.


int qualityValue = 90;


ByteArrayOutputStream bout = new ByteArrayOutputStream();


chemaxon.marvin.modules.JpegEncoder encoder = new chemaxon.marvin.modules.JpegEncoder(img, qualityValue, bout);


encoder.Compress(null);


byte[] data = bout.toByteArray();





// save data into a file


if(data != null) {


OutputStream out = new FileOutputStream("output.jpeg");


out.write(data);


out.close();


}


User d68ef9d5a9

23-12-2005 15:17:28

Thank you, Tamas, for your help.





If I need PNG image format, how can I get image in in PNG file. I tried chemaxon.marvin.modules.PngEncoder. It doesn't work.





Ben Li

ChemAxon 7c2d26e5cf

28-12-2005 11:19:59

Modify the proper part of the previous example like this:
Quote:
// convert Image into an OutputStream to be able to save it.


chemaxon.marvin.modules.PngEncoder encoder = new chemaxon.marvin.modules.PngEncoder(img, false);


byte[] data = encoder.pngEncode();
The second parameter in the constructor of PngEncoder is encodeAlpha. If you set it to true, the encoder will encode the alpha channel.

User d68ef9d5a9

28-12-2005 19:52:21

Hi Tamas,





Thank you for your help. I am able to get PNG files using your codes.





However, the quality of molecules is still not ideal to us. Setting wire thickniss to 0.1 improved some molecules, but wouldn't help those big molecules. I have two files attached. For the clearMolecule, the bonds and elements are good. But for the blurMolecule, the molecular size is doubled the size for previous one. The darkness of bonds and elements is reduced probably proportionally based on the molecule size and image size. My question is: how can I force the bonds (elements) as dark as the clearMolecule. I want both images to stay at the same sharpness. Is this possible? How? Thank you for your time.





Ben Li

ChemAxon 7c2d26e5cf

30-12-2005 11:42:58

I suggest you to switch off anti-aliasing drawing. You can do it with the MarvinPane.setDispQuality(int) method:


Code:
sketchpane.setDispQuality(0)



In Marvin, high quality display mode means the anti-aliasing drawing. If you choose low quality mode, anti-aliasing will be switched off.


Anti-aliasing provides softer line drawing but its disadvantage is that the line will be blur if the line is too thin. In this case we suggest the low quality display mode.


You can read more about anti-aliasing in Wikipedia.

User d68ef9d5a9

03-01-2006 15:45:16

Thank you, Tamas.





Using dispQuality(0) generates images without anti-aliasing. This is a great help for us. But the quality of the images is still not ideal for us. The solid lines appears to be dash-like lines. Is there any way to keep the line solid without anti-aliasing?





Appreciate your time.





Ben Li

ChemAxon 7c2d26e5cf

03-01-2006 17:44:27

Quote:
Is there any way to keep the line solid without anti-aliasing?
No, it is not possible.


You can play with two parameters: anti-aliasing and bond thickness. If the low quality image is not suitable for you, use the high quality image with increased bond thickness.

User d68ef9d5a9

18-08-2006 15:39:11

Hi,





I try to pick the image quality topic again this time. Attached please find molecule images from JChem and ISIS. The JChem image is generated by the codes you suggested before (see previous message under same topic). I am seeking way to make to molecule images as good as ISIS can provide. I have played around with wire thickness and anti-aliasing, but cannot get a clean and sharp image.





Recently, I heard from Ferenc that there are options to get images with publishable quality. I guess that is what I need. As I cannot find any information in JChem document about this option, would you please give me an example how to get that kind of images programmatically?





Thank you for your time.





Ben Li

ChemAxon 7c2d26e5cf

21-08-2006 08:36:58

Publishable quality (format bonds and atom labels) is a new feature that is available from Marvin 4.1. The latest stable JChem version includes an earlier version of Marvin. The new JChem that contains Marvin 4.1 is not released yet.


A test version of the new JChem is already available.


http://www.chemaxon.com/download.php?d=/data/download/jchem/test


You can read more about it in the following topic: http://www.chemaxon.com/forum/viewtopic.php?p=7535#7535

User d68ef9d5a9

22-09-2006 14:02:23

Hi,





I have a question related to this topic. I try to send thepng image directly to web page through servlet. I do not want to same a image file one the server and then post the image file to web pages.





The codes I am using look like:





//http servlet response: resp


ServletOutputStream out=resp.getOutputStream();


resp.setContentType("image/png");





chemaxon.marvin.modules.PngEncoder encoder = new chemaxon.marvin.modules.PngEncoder(img, false);


byte[] data = encoder.pngEncode();


for (int i=0; i<code.length; i++){


out.print(code);


}





What I got is the binary codes on html page, not the image. Would you please let me know what is the problem?





By the way, do you have GifEncoder? If yes, how to use it in this situation?





In my case, either png or gif will be fine, but we prefer png.





Ben Li

User d68ef9d5a9

22-09-2006 14:05:05

The line [byte[] data = encoder.pngEncode(); ] in above message should be





byte[] code = encoder.pngEncode();

User d68ef9d5a9

22-09-2006 15:35:26

Hi,





I have solved the problem I just posted here.





The solution is very easy. I post here to share with other developers:





ByteArrayInputStream input=new ByteArrayInputStream(code);


BufferedImage bimg=ImageIO.read(input);


ImageIO.write(bimg, "png", out);





Cheers,





Ben

ChemAxon 7c2d26e5cf

22-09-2006 15:58:26

Great. :)


By the way, currently, we haven't got GIF export. But we plan to implement it.