Simple get coordinates plugin not working for 2000x2000 above images


I have created below plugin to get coordinates of an image. The plugin seems to work fine for the image resolutions below 2000x2000, but for images between 2000x2000 upto 3000x3000 the coordinates I get are half the resolution. For images above 3000 its 1/3, for 4000 above is 1/4 and so on. Could anyone please look into my plugin and explain me why is it doing so.
Many thanks.

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

public class get_Coords extends PlugInFrame implements MouseListener {
	ImagePlus tempimp;
	int imageWidth;
	int imageHeight;
	ImageCanvas canvas;
	public void run(String arg) {

	public boolean OpenImageDialog(){
		OpenDialog od = new OpenDialog("Select Image");
		if(od.getDirectory() == null){
			return false;
		String fileDirectory = od.getDirectory() + od.getFileName();		
		ImagePlus imp = new ImagePlus(fileDirectory);
		tempimp = imp;;
		imageWidth = imp.getWidth();
		imageHeight = imp.getHeight();
		IJ.log("Image Plus width : "  + imageWidth + " and height : " + imageHeight);
		ImageWindow win = imp.getWindow();
		canvas = win.getCanvas();
		return true;
	public void mousePressed(MouseEvent e) {		
		int x = e.getX();
		int y = e.getY();
		IJ.log("x : " + x + " y : " + y);

	public void mouseReleased(MouseEvent e) { }
	public void mouseEntered(MouseEvent e) {}
	public void mouseExited(MouseEvent e) {}
	public void mouseClicked(MouseEvent e) {}	
	public get_Coords () {

You are getting the screen coordinates. The values are changing if you are zooming in or out according to the visible canvas coordinates. You have to apply the the transformation to the image coordinates, e.g. simply with:

    public void mousePressed(MouseEvent e) {		
    		int x = canvas.offScreenX(e.getX());
                int y = canvas.offScreenX(e.getY());
    		IJ.log("x : " + x + " y : " + y);


(also for floating point coordinates if required)


Thanks very much Bio7, it works perfectly.