|
Hi, i was wondering if someone could spot where im going wrong here in this
code.
I want to take two cropped images from user drawn Roi's and superimpose them
on top of each other(this part works fine). But when i want to nudge one of
the images in a given direction, I can't manage to pull it off.
the problem line of code is the second from the bottom
here it is
public void actionPerformed(ActionEvent e){
imp = WindowManager.getCurrentImage();
ip = imp.getProcessor();
if(e.getSource() == copyButton){
copyCount++;
//first image to be cropped
if(copyCount == NO_IMAGE_CROPPED){
firstAddIP = ip.crop();
r1 = ip.getRoi();
}
second image to be cropped
else if(copyCount == ONE_IMAGE_CROPPED){
secondAddIP = ip.crop();
r2 = ip.getRoi();
combinedImage = new ImagePlus("combined Image", firstAddIP);
combinedImageIP = combinedImage.getProcessor();
//combine both cropped images
combinedImageIP.copyBits(secondAddIP, 0, 0, Blitter.ADD);
combinedImage.updateAndDraw();
combinedImage.show();
}
}
else if(e.getSource() == northButton){
moveImage(NORTH);
}
else if(e.getSource() == eastButton){
moveImage(EAST);
}
else if(e.getSource() == southButton){
moveImage(SOUTH);
}
else if(e.getSource() == westButton){
moveImage(WEST);
}
}
public void moveImage(int direction){
// subtract the latest crop from the combined image
combinedImageIP.copyBits(secondAddIP, 0, 0, Blitter.SUBTRACT);
//nudge the ip Roi upon button presses
if(direction == NORTH){
r2.y--;
ip.setRoi(r2);
}
else if(direction == EAST){
r2.x++;
ip.setRoi(r2);
}
else if(direction == SOUTH){
r2.y++;
ip.setRoi(r2);
}
else if(direction == WEST){
r2.x--;
ip.setRoi(r2);
}
//this line of code gives me the problems, doesn't do what I want it
to do, that is superimpose the nudge Roi from ip onto the pixel data fromthe
first cropped image
combinedImageIP.copyBits(ip.crop(), 0, 0, Blitter.ADD);
combinedImage.updateAndDraw();
}
I'm sure its something simple about how I am using the imageProcessor
variables but I haven't been able to work it out.
|