ImageJ, adding a scale bar to ImagePlus

I am trying to add a scale bar to ImagePlus but I can not. When I was using windows I used the following commands:

IJ.selectWindow("window_name"); IJ.run("Set Scale...", "distance=1 known="+pixelSize+" pixel=1 unit=um"); IJ.run("Scale Bar...", "width="+barSize+" height=3 font=12 color=Black location=[Upper Right]");

I hope someone can help me, I let the code to be seen:

String name = "example.jpg"; ImagePlus cRoiDuplicated = this.cROI.duplicate(); cRoiDuplicated.setTitle(name); if (barSize != -1){ [Code] /*IJ.run("Set Scale...", "distance=1 known="+pixelSize+" pixel=1 unit=um"); IJ.run("Scale Bar...", "width="+barSize+" height=3 font=12 color=Black location=[Upper Right]");*/ } FileSaver fs = new FileSaver(cRoiDuplicated); fs.saveAsJpeg(this.directory + name); cRoiDuplicated.close();

-------------Problems Reply------------

In a Java plugin, you should use the IJ.run(ImagePlus imp, String command, String options) method that takes an ImagePlus as first input argument.

Use the Macro recorder in Java mode to get the required commands. The following plugin was created by

  • opening the recorder window (Plugins > Macros > Record...),
  • opening the 'Blobs' sample image (File > Open Samples > Blobs (25K)),
  • setting the scale (Analyze > Set Scale...),
  • adding the scale bar (Analyze > Tools > Scale Bar...), and then
  • clicking on the 'Create' button in the Recorder window.

This is the generated code:

import ij.*;
import ij.process.*;
import ij.gui.*;
import java.awt.*;
import ij.plugin.*;
import ij.plugin.frame.*;

public class My_Plugin implements PlugIn {

public void run(String arg) {
ImagePlus imp = IJ.openImage("http://imagej.nih.gov/ij/images/blobs.gif");
IJ.run(imp, "Set Scale...", "distance=1 known=2 pixel=1 unit=um");
IJ.run(imp, "Scale Bar...", "width=50 height=3 font=12 color=Black background=None location=[Upper right]");
imp.show();
}

}

Category:java Views:0 Time:2018-03-27

Related post

  • Adding scale bars 2014-01-05

    problem : I have a micrograph ( an optically zoomed image ) with known magnification ( say 100x ). I wish to add a scale bar to the image. (for example, if the actual distance between two points is 100 micrometers, at 100x, it's apparent length in th

  • How do I add a scale bar to a plot in Mayavi2/VTK? 2011-07-14

    I would like to add a scale bar (showing how big a micron is for example) to a mayavi plot I create with mlab. For example, referencing this question: How to display a volume with non-cubic voxels correctly in mayavi I can set the voxel size of a plo

  • Horizontal scale bar in R plot 2010-07-22

    When I plot my fitted models in R, I get the output with a vertical scale bar. Can some one kindly tell me how to place a horizontal scale bar in R plots instead of vertical? Thanks in advance.

  • How do I add a scale bar or north arrow directly on the map control? 2010-12-11

    I've already looked into SurroundFrames and MapSurrounds, but this appears to be for cases in which you want to add these elements to a printed page. I, on the other hand, am using the MapControl within a live application, and I would like these elem

  • how to draw a vertical scale bar with css 2011-09-30

    i want to draw a vertical scale bar with css for my project. please help me. here u can see the image. http://www.google.co.in/imgres?q=vertical+scale+bar&um=1&hl=en&sa=N&biw=1024&bih=578&tbm=isch&tbnid=FJiiXsutIEBcKM:

  • mqsicreatebar "cannot be added to the BAR file because it does not contain any input nodes" 2011-10-21

    I'm using Websphere Message Broker Toolkit 7 and am trying to create an automated bar build. whilst running the following command I'm getting the following error: mqsicreatebar -data C:\temp -b test.bar -cleanBuild-p "CDC Adaptor" -o "C:\temp\UpdateQ

  • WPF Bing Maps Control - Change Scale Bar Units 2011-10-26

    I'm trying out the Bing Maps control for WPF and this is driving me mad. I can't figure out how to access the built-in scale bar so I can change the units to metric. I can add a new scale bar, compass, etc. just fine but can't access the default one.

  • Can Location/Scale bar be permanently turned off? 2013-09-29

    Every time I open a map the Location/Scale bar is displaying. I turn it off and save the map, but the next time I open the map the bar is there again. Can I permanently turn off the Location/Scale bar? --------------Solutions------------- Hello Golde

  • Is it possible to provide a resize indication (resizer-grip) on a form without adding a status bar? 2009-10-14

    I would like to have a resize indication on a windows forms Form (the same resize-grip as when you have a status bar). I do not want to add a status bar to the form - that would break the design of the form. The form can have various controls inside

  • Adding a button bar at the bottom of ListView upon checkbox select (as in Gmail app)? 2011-01-02

    I have a ListView with custom adapter. In each row there is a checkbox and couple of textviews. I want user to give option to delete the check marked items, so as soon as soon clicks on one of the checkbox, I want a button bar to slide in from the bo

  • Adding space between bars in ggplot2 2011-05-22

    Dear all, I'd like to add spaces between bars in ggplot2. This page offers one solution: http://www.streamreader.org/stats/questions/6204/how-to-increase-the-space-between-the-bars-in-a-bar-plot-in-ggplot2. Instead of using factor levels for the x-ax

  • Problem adding vertical scroll bar to iFrame 2011-08-26

    I have added a vertical scroll bar to my iFrame which is created through JS. The iFrame contents are set dynamically i.e user can add fields to this iFrame.when the height of the frame goes beyond the limit the upper fields get hidden.how can this pr

  • Adding UISearchBar programatically - Bar is Off Screen at Launch - iPad 2011-09-29

    I have added a UISearchBar to a table in my iPad app using the below code. The table is on the left hand side of my split view controller. The problem is that when the app starts the search bar is strangely off screen to the left - you can just see t

  • Adding add-on bar to a custom XULRunner application 2011-11-30

    On MDN, the phrase "Add-on Manager-enabled XUL application" is introduced. By dragging a XPI file containing an add-on and dropping it onto a FireFox window, the addon's widgets will be installed in FireFox's add-on bar. I can also use Firefox to run

  • Adding to Favorites Bar Produces Two Icons 2012-08-31

    Hello, Why does IE8 produce two icons for the urls added to the favorite bar? One of them is the URL while other one appears to be a title or something. Is this something that can be turned off? Thanks --------------Solutions------------- Possible cu

  • Interface builder added one tab bar button, but not showing up 2009-03-31

    I replaced one tab bar button in interface builder. It was "Recent" button, I changed it to "Contacts" button. Now the tab bar button not showing up, but I could click on that position, and action does work. The neighbor unchanged tab bars have no pr

  • Adding a tool bar to a web page 2010-02-24

    I want to add a tool bar (just like the one above the text area where we type our questions in this forum , with bold,italic etc) to a web page.Is there an easier way of doing this?I am using ASP.Net c# and VS2008. Thankx in advance. --------------So

  • Adding a navigation bar to a web view in a tab bar app 2010-05-27

    I've built the tab bar application in IB, with three tabs. The third tab happily displays a UIWebview where you can browse. The only thing missing is a back button, as not all web pages supply such a link. I need a navigation bar hooked up properly t

  • Objective C adding a tab bar item to change to other views 2010-08-31

    I Have a normal view based application and have added an UITabBar component. I have found help how to create a tabbar app but nothing about how to use the UITabbar item separately How may I use this to switch views please? --------------Solutions----

  • What new features will be added to Scala 2.9? 2010-10-10

    I know parallel collections will become available. What form will these take, and what else are we likely to see? --------------Solutions------------- For the full list, see: Beyond 2.8 - A Roadmap The main thing seems to be parallel collections. The

  • Adding a scroll bar if div extends below bottom of view port 2010-12-03

    I have a <div> in my page which contains a <table> of varying number of rows, i.e varying height: <html> <head></head> <body> <div> <table> <tr>... <tr>... ... </table> </div>

  • events for Custom Expanded View added to Status Bar Notifications? 2011-02-27

    from this link i am able to add views to status bar. http://developer.android.com/guide/topics/ui/notifiers/notifications.html. but how to define events for it. suppose i am addind two buttons than how can i set onclick events for buttons. this is my

  • Adding a scroll bar to MS Chart control C# 2011-02-28

    please understand that I know there are other threads concerning this issue, but my needs are different. Basically before I seen people saying to implement a scroll bar with MSChart they use the .Size = ... or .View = ... But, this make a scroll bar

  • Adding a scroll bar to a label 2011-04-14

    I have a label on a userForm and the data within it is in list form. The data is longer than the label. Without expanding the label, is there a way to add a scroll bar to it? Or is there another option? Basically I want a box that does not have a scr

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.092 (s). 11 q(s)