Gray-scale SEM Microscopy Image to Beautiful Color Rendering? - image

do you know of any Open Source software that could help me perform such a thing: converting a gray-scale image to an eye-catching colorful rendering. I was thinking about ImageMagick (along with EBImage package) or Gimp while resorting to a Script-Fu. Also, being able to automate the process would be great.
I thank you for sharing a fraction of your valuable time in answering my question.
Good day,
Raphael

You looking for LookUp Tables (LUT). See ImageJ wiki.
Just install ImageJ or it's Fiji distribution, open your image and select Image > Lookup Tables > Choose one nice. If your image is not really grayscale (not one-channel), program raises an exception like LUTs cannot be assigned to RGB images. If so, select Image > Type > 8-bit and apply LUT again.
Use macros or language bindings (I use Jython) for automation.

Related

Matplotlib Plots Lose Transparency When Saving as .ps/.eps

I'm having an issue with attempting to save some plots with transparent ellipsoids on them if I attempt to save them with .ps/.eps extensions.
Here's the plot saved as a .png:
If I choose to save it as a .ps/.eps here is what it looks like:
How I got around this, was to use ImageMagick to convert the original png to a ps. The only problem is that the image in png format is about 90k, and it becomes just under 4M after conversion. This is not good since I have a lot of these images, and it will take too much time to compile my latex document. Does anyone have a solution to this?
The problem is that eps does not support transparencies natively.
There are few options:
rasterize the image and embed in a eps file (like #Molly suggests) or exporting to pdf and converting with some external tool (like gs) (which usually relies as well on rasterization)
'mimic' transparency, giving a colour that looks like the transparent one on a given background.
I discussed this for sure once on the matplotlib mailing list, and I got the suggestion to rasterize, which is not feasible as you get either pixellized or huge figures. And they don't scale very nicely when put into, e.g., a publication.
I personally use the second approach, and although not ideal, I found it good enough. I wrote a small python script that implements the algorithm from this SO post to obtain a solid RGB representation of a colour with a give transparency
EDIT
In the specific case of your plot try to use the zorder keyword to order the parts plotted. Try to use zorder=10 for the blue ellipse, zorder=11 for the green and zorder=12 for the hexbins.
This way the blue should be below everything, then the green ellipse and finally the hexbins. And the plot should be readable also with solid colors. And if you like the shades of blue and green that you have in png, you can try to play with mimic_alpha.py.
EDIT 2
If you are 100% sure that you have to use eps, there are a couple of workarounds that come to my mind (and that are definitely uglier than your plot):
Just draw the ellipse borders on top of the hexbins.
Get centre and amplitude of each hexagon, (possibly discard all zero bins) and make a scatter plot using the same colour map as in hexbin and adjusting the marker size and shape as you like. You might want to redraw the ellipses borders on top of that
Another alternative would be to save them to pdf
savefig('myfigure.pdf')
That works with pdflatex, if that was the reason why you needed to use eps and not svg.
You can rasterize the figure before saving it to preserve transparency in the eps file:
ax.set_rasterized(True)
plt.savefig('rasterized_fig.eps')
I had the same problem. To avoid rasterizing, you can save the image as a pdf and then run (on unixish systems at least) in a terminal:
pdftops -eps my.pdf my.eps
Which gives a .eps file as output.
I solved this by:
1) adding a set_rasterization_zorder(1) when defining the figure area:
fxsize=16
fysize=8
f = figure(num=None, figsize=(fxsize, fysize), dpi=180, facecolor='w',
edgecolor='k')
plt.subplots_adjust(
left = (18/25.4)/fxsize,
bottom = (13/25.4)/fysize,
right = 1 - (8/25.4)/fxsize,
top = 1 - (8/25.4)/fysize)
subplots_adjust(hspace=0,wspace=0.1)
#f.suptitle('An overall title', size=20)
gs0 = gridspec.GridSpec(1, 2)
gs11 = gridspec.GridSpecFromSubplotSpec(1, 1, subplot_spec=gs0[0])
ax110 = plt.Subplot(f, gs11[0,0])
f.add_subplot(ax110)
ax110.set_rasterization_zorder(1)
2) a zorder=0 in each alpha=anynumber in the plot:
ax110.scatter(xs1,ys1 , marker='o', color='gray' , s=1.5,zorder=0,alpha=0.3)#, label=label_bg)
and
3) finally a rasterized=True when saving:
P.savefig(str(PLOTFILENAME)+'.eps', rasterized=True)
Note that this may not work as expected with the transparent keyword to savefig because an RGBA colour with alpha<1 on transparent background will be rendered the same as the RGB colour with alpha=1.
As mentioned above, the best and easiest choice (if you do not want to loose resolution) is to rasterized the figure
f = plt.figure()
f.set_rasterized(True)
ax = f.add_subplot(111)
ax.set_rasterized(True)
f.savefig('figure_name.eps',rasterized=True,dpi=300)
This way, you can manage the size by dpi option as well. In fact, you can also play with the zorder below you want to apply the rasterization:
ax.set_rasterization_zorder(0)
Note: It is important to keep f.set_rasterized(True) when you use plt.subplot and plt.subplot2grid functions. Otherwise, label and tick area will not appear in the .eps file
My solution is to export the plot as .eps, load it up to Inkscape for example, then Ungroup the plot, select the object that I want to set the transparency and just edit the Opacity of the Fill in the "Fill and Stroke" tab.
You can save the file as .svg if you want to tweak it later, or export the image for a publication.
If you are writing the academic paper in latex, I would recommend you export the .pdf file rather than .eps. The .pdf format supports transparency perfectly and has good compression efficiency, and most importantly, can be easily edited in Adobe Illustrator.
If you wanna further edit the graph (NOT EDITING DATA! I MEAN, FOR GOOD-LOOKING), you could open the exported graph, in Adobe Acrobat - Edit - Copy elements into Adobe Illustrator. The two software can handle everything perfectly.
I work happily with this method. Everything clear, editable and small-size. Hope can help.

Reduce size of a .png image without losing transparency

Basically, I'd like to resize or resample a .png image (in order to reduce its file size) and yet retain it's transparency.
Anybody got an idea how best to go about this?
Thanks.
You can use paint.net, it is a free tool. Although it is pretty basic, it does the job.
Go to Image > Resize
Stumbled upon this thread and found the following site that does exactly what is requested: https://onlinepngtools.com/resize-png
What graphics program are you using?
Photoshop does this by simply going thru IMAGE > IMAGE SIZE and resizing. Transparency is not affected.
I'm sure Paint Shop Pro does the same
I know this is an old question, but the answer that worked for me was to use Inkscape.
Start Inkscape (free on Inkscape.org).
File -> Import... (Ctrl+I) the PNG file you want to resize (defaults on import dialog are ok).
With the image you just imported selected, select File -> Export PNG image... (Shift+Ctrl+E)
In the Export PNG Image tool pane, click the Export As... button to set the output filename and location.
In this same tool pane, set the image size using width/height or pixels.
In this same tool pane, click the Export button to create the output file.
This worked for me, hope it helps someone else.
Providing the image you have created / have been working on is transparent in the first place, using the "Resize" or "Resample" tools in any major image editing package (e.g. PhotoShop, PaintShop Pro and so on) should not affect (or lose) the transparency at all.
I use PaintShop Pro (X6, 64 Bit) myself and typically find that the "PNG Optimizer" option offers more options along these lines (than the default "Save As > .png" route).
Hope that this helps (specific to PaintShop Pro Users) in relation to the source question.
While I was waiting for the downloads of other image editing softwares, I tried Microsoft Power Point and succeeded in preserving the transparency.
Drag the image inside any slide, crop or resize, then save as a new picture as .png.
You can drag the image back in ppt to confirm the transparency is maintained
The complete Autodesk Sketchbook is now out for free including all the previous premium features such as resizing an image.
You do it as you would in paint by clicking on Image > Image Size... and then you can save as a .png without losing transparency.
Image size can be reduced by reducing number of colors and there are online tools to do this .
Try these..Hope they solve your problem
https://tinypng.com/‎
http://pngcrush.com/ and
http://tools.dynamicdrive.com/imageoptimizer/ --It provides more output images with different number of colors. However, smoothness will be effected, take care.

Picture Transparency

How do I make a picture transparent in VB6.0 so that when I add image and put the picture, the background will show behind it?
From Rod Stephen's excellent VB Helper site (particularly good on graphics in VB6):
HowTo: Overlay one image on another with a transparent color by using PSet
Description from the site:
This program simply loops through the pixels in the images. For each
image in top-to-bottom order, the program looks for a color other than
the one defined as transparent. When it finds such a color, it stops
looking at the images and sets the output pixel's color using PSet.
Note that there are faster ways to access color values in V 6 and VB
.NET, and that there are faster methods for merging images if you have
an overlay mask. Note also that VB .NET provides tools for setting a
transparent color for an image so this problem is trivial in VB .NET.
i think you should use an ocx and dll library to fix it
You can use 3rd party .ocx files to get that effect.checkout this link http://www.vbforums.com/showthread.php?636390-vb6-Transparent-PictureBox

HDR image creating algorithm

Do you know any algorithm to create HDR images, like photomatix or photoshop "merge hdr" function?
Are you referring to Pseudo HDR (HDR look from 1 image) or HDR from few different images (Each with different Exposure)?
Usually HDR starts with Edge Preserving Smoothing operator.
This allows to differentiate between the details, where we want to keep data, to flat areas, where we can compress the data.
The next step would be applying a compressing function to the data we want to compress.
The last step would be to blend the compressed data.
I would start by reading about Tone Mapping:
http://en.wikipedia.org/wiki/Tone_mapping
Matlab has merge HDR function. If you have matlab installed, you can get source code of it in installation directory.(but you cannot use it for licensed app).
For few more details:
Open Source HDR library recommendations
I would suggest the HDR Toolbox which has open source (GPL v3) code and advanced alignment modes:
https://github.com/banterle/HDR_Toolbox/tree/master/source_code/Generation
http://www.advancedhdrbook.com
I don't know what language you use, but you can always take a look at the source code for Luminance (Qtpfsgui) and see how they do it.
Remember though, that that code is copyrighted so you can't really copy & paste into a differently licensed app.

Blurred colors using epsfig or graphicx in LaTeX

My code is simple enough, and importing eps images is something I've done before with other matlab-generated content, but for one reason or another I end up with blurred colors in my heatmap when I use epsfig or graphicx to import it into my document. In the picture below, the right is what shows up if I compile to DVI and open up the document in Yap, and the left is if I simply view the eps in GSView.
alt text http://img85.imageshack.us/img85/1694/epsproblem.png
Here is my code. This example is using graphicx, but the idea is the same with epsfig.
\begin{figure}
\centering
\includegraphics[scale=0.5]{images/ngram3_model_raw.eps}
\caption{The perplexity when compared
against the HUB test set}
\end{figure}
Is there perhaps some option I am forgetting?
I had the same problem with DVI, but if I compiled to pdf the pictures were fine
What you see is bilinear interpolation. It is done by the viewer. Probably Matlab defines the plot contents as a pixmap (I guess you use imagesc?).
The solution is not straightforward. It may help to use a different processing chain (as WtFudgE pointed out) that will lead the data end up in a format where it is not interpolated anymore. You may also use a different viewer that does not interpolate and I would assume that a printer would also not interpolate. This can again be dependent of the application you print from.
Sorry that I don't have a solution for you; at least you now have some new words to search for in Google. ;)

Resources