# Find Dimension of Raw Image

## Purpose

This script serves two purposes:

• to demonstrate that an AWT Listener can be written in Jython, and
• to find the width of an image you know is uncompressed, but do not know the dimensions.

To use it, open the raw image with File › Import › Raw… choosing a width and height that should roughly be the correct one. Then start this script, which will open a dialog box with a slider, with which you can interactively test new widths – the pixels in the image window will be updated accordingly.

The script is maintained by Johannes Schindelin .

## Code

# This script serves two purposes:
#
# - to demonstrate that an AWT Listener can be written in Jython, and
#
# - to find the width of an image you know is uncompressed, but do not know
#   the dimensions.
#
# To use it, open the raw image with <span class="bc">File  ›  Import  ›  Raw...</span>  choosing a width and
# height that should roughly be the correct one.  Then start this script,
# which will open a dialog box with a slider, with which you can interactively
# test new widths -- the pixels in the image window will be updated accordingly.

from ij.gui import GenericDialog

from java.lang import Math, System

image = WindowManager.getCurrentImage()
ip = image.getProcessor()
pixelsCopy = ip.getPixelsCopy()
pixels = ip.getPixels()
width = ip.getWidth()
height = ip.getHeight()

minWidth = int(Math.sqrt(len(pixels) / 16))
maxWidth = minWidth * 16

value = event.getSource().getValue()
rowstride = min(width, value)
for j in range(0, min(height, int(width * height / value))):
System.arraycopy(pixelsCopy, j * value,
pixels, j * width, rowstride)
image.updateAndDraw()

gd = GenericDialog("Width")