import ij.IJ;
import ij.ImagePlus;
import ij.WindowManager;
import ij.process.*;
import ij.gui.GenericDialog;
import java.awt.*;
import ij.plugin.filter.*;
public class movimiento implements PlugInFilter {
ImagePlus fgIm = null;
static double alpha = 0.5;
public int setup(String arg, ImagePlus img) {
return DOES_8G;
}
public void run(ImageProcessor bgIp) {
if(runDialog()){
ImageProcessor fgIp=fgIm.getProcessor().convertToByte(false);
fgIp = fgIp.duplicate();
bgIp.copyBits(fgIp, 0, 0, Blitter.DIFFERENCE);
int w=bgIp.getWidth();
int n=bgIp.getHeight();
for(int i =0; i < w; i++)
{
for(int j= 0; j < n; j++)
{
int p =bgIp.getPixel(i,j);
if (p < 150){
p=0;
}else if(p >= 150){
p=255;
}
bgIp.putPixel(i,j,p);
}
}
}
}
boolean runDialog(){
int[] windowList = WindowManager.getIDList();
if (windowList == null){
IJ.noImage();
return false;
}
String[] windowTitles = new String[windowList.length];
for(int i = 0; i < windowList.length; i++)
{
ImagePlus im = WindowManager.getImage (windowList[i]);
if (im == null)
windowTitles[i] = "untitled";
else
windowTitles[i] = im.getShortTitle();
}
GenericDialog gd = new GenericDialog("Alpha Blending");
gd.addChoice("Foreground image: ", windowTitles, windowTitles[0]);
gd. addNumericField("Alpha value [0. . 1]: " , alpha, 2);
gd.showDialog();
if (gd.wasCanceled())
return false;
else {
int fgIdx = gd.getNextChoiceIndex();
fgIm = WindowManager.getImage(windowList[fgIdx]);
alpha = gd.getNextNumber ();
return true;
}
}
}
martes, 3 de marzo de 2009
miércoles, 25 de febrero de 2009
Manipulación de dos imágenes para realizar un montaje, usando código en Java
El código implementado nos indica que se procede a mezclar dos imágenes una como (background), imagen de fondo y la otra imagen (foreground)para ser montada sobre la primera.
La imagen background es multiplicada por un número alpha, la imagen foreground en primera instancia es duplicada y luego multiplicada por el número alpha con lo cual la imagen original (background no se modificará), dando como resultado una mezcla de las dos imágenes citadas.
A continuación se inserta el código.
import ij.IJ;
import ij.ImagePlus;
import ij.WindowManager;
import ij.process.*;
import ij.gui.GenericDialog;
import java.awt.*;
import ij.plugin.filter.*;
public class Alpha_Blending implements PlugInFilter {
ImagePlus fgIm = null;
static double alpha = 0.5;
public int setup(String arg, ImagePlus img) {
return DOES_8G;
}
public void run(ImageProcessor bgIp) {
if(runDialog()){
ImageProcessor fgIp=fgIm.getProcessor().convertToByte(false);
fgIp = fgIp.duplicate();
fgIp.multiply(1-alpha);
bgIp.multiply(alpha);
bgIp.copyBits(fgIp, 0, 0, Blitter.ADD);
}
}
boolean runDialog(){
int[] windowList = WindowManager.getIDList();
if (windowList == null){
IJ.noImage();
return false;
}
String[] windowTitles = new String[windowList.length];
for(int i = 0; i < windowList.length; i++)
{
ImagePlus im = WindowManager.getImage (windowList[i]);
if (im == null)
windowTitles[i] = "untitled";
else
windowTitles[i] = im.getShortTitle();
}
GenericDialog gd = new GenericDialog("Alpha Blending");
gd.addChoice("Foreground image: ", windowTitles, windowTitles[0]);
gd. addNumericField("Alpha value [0. . 1]: " , alpha, 2);
gd.showDialog();
if (gd.wasCanceled())
return false;
else {
int fgIdx = gd.getNextChoiceIndex();
fgIm = WindowManager.getImage(windowList[fgIdx]);
alpha = gd.getNextNumber ();
return true;
}
}
}
La imagen background es multiplicada por un número alpha, la imagen foreground en primera instancia es duplicada y luego multiplicada por el número alpha con lo cual la imagen original (background no se modificará), dando como resultado una mezcla de las dos imágenes citadas.
A continuación se inserta el código.
import ij.IJ;
import ij.ImagePlus;
import ij.WindowManager;
import ij.process.*;
import ij.gui.GenericDialog;
import java.awt.*;
import ij.plugin.filter.*;
public class Alpha_Blending implements PlugInFilter {
ImagePlus fgIm = null;
static double alpha = 0.5;
public int setup(String arg, ImagePlus img) {
return DOES_8G;
}
public void run(ImageProcessor bgIp) {
if(runDialog()){
ImageProcessor fgIp=fgIm.getProcessor().convertToByte(false);
fgIp = fgIp.duplicate();
fgIp.multiply(1-alpha);
bgIp.multiply(alpha);
bgIp.copyBits(fgIp, 0, 0, Blitter.ADD);
}
}
boolean runDialog(){
int[] windowList = WindowManager.getIDList();
if (windowList == null){
IJ.noImage();
return false;
}
String[] windowTitles = new String[windowList.length];
for(int i = 0; i < windowList.length; i++)
{
ImagePlus im = WindowManager.getImage (windowList[i]);
if (im == null)
windowTitles[i] = "untitled";
else
windowTitles[i] = im.getShortTitle();
}
GenericDialog gd = new GenericDialog("Alpha Blending");
gd.addChoice("Foreground image: ", windowTitles, windowTitles[0]);
gd. addNumericField("Alpha value [0. . 1]: " , alpha, 2);
gd.showDialog();
if (gd.wasCanceled())
return false;
else {
int fgIdx = gd.getNextChoiceIndex();
fgIm = WindowManager.getImage(windowList[fgIdx]);
alpha = gd.getNextNumber ();
return true;
}
}
}
Control Movimiento
import ij.IJ;
import ij.ImagePlus;
import ij.WindowManager;
import ij.process.*;
import ij.gui.GenericDialog;
import java.awt.*;
import ij.plugin.filter.*;
public class Control_Moviento implements PlugInFilter
{
ImagePlus fgIm = null;
static double alpha = 0.5;
public int setup(String arg, ImagePlus img)
{
return DOES_8G;
}
public void run(ImageProcessor bgIp)
{
if(runDialog())
{
ImageProcessor fgIp=fgIm.getProcessor().convertToByte(false);
fgIp = fgIp.duplicate();
bgIp.copyBits(fgIp, 0, 0, Blitter.DIFFERENCE);
int w=bgIp.getWidth();
int n=bgIp.getHeight();
for(int i =0; i < w;i++)
{
for(int j= 0; j < n;j++)
{
int p =bgIp.getPixel(i,j);
if (p <150)
{
p=0;
}else if(p>=150)
{
p=255;
}
bgIp.putPixel(i,j,p);
}
}
}
}
boolean runDialog(){
int[] windowList = WindowManager.getIDList();
if (windowList == null){
IJ.noImage();
return false;
}
String[] windowTitles = new String[windowList.length];
for(int i = 0; i < windowList.length; i++)
{
ImagePlus im = WindowManager.getImage (windowList[i]);
if (im == null)
windowTitles[i] = "untitled";
else
windowTitles[i] = im.getShortTitle();
}
GenericDialog gd = new GenericDialog("Alpha Blending");
gd.addChoice("Foreground image: ", windowTitles, windowTitles[0]);
gd. addNumericField("Alpha value [0. . 1]: " , alpha, 2);
gd.showDialog();
if (gd.wasCanceled())
return false;
else {
int fgIdx = gd.getNextChoiceIndex();
fgIm = WindowManager.getImage(windowList[fgIdx]);
alpha = gd.getNextNumber ();
return true;
}
}
}
import ij.ImagePlus;
import ij.WindowManager;
import ij.process.*;
import ij.gui.GenericDialog;
import java.awt.*;
import ij.plugin.filter.*;
public class Control_Moviento implements PlugInFilter
{
ImagePlus fgIm = null;
static double alpha = 0.5;
public int setup(String arg, ImagePlus img)
{
return DOES_8G;
}
public void run(ImageProcessor bgIp)
{
if(runDialog())
{
ImageProcessor fgIp=fgIm.getProcessor().convertToByte(false);
fgIp = fgIp.duplicate();
bgIp.copyBits(fgIp, 0, 0, Blitter.DIFFERENCE);
int w=bgIp.getWidth();
int n=bgIp.getHeight();
for(int i =0; i < w;i++)
{
for(int j= 0; j < n;j++)
{
int p =bgIp.getPixel(i,j);
if (p <150)
{
p=0;
}else if(p>=150)
{
p=255;
}
bgIp.putPixel(i,j,p);
}
}
}
}
boolean runDialog(){
int[] windowList = WindowManager.getIDList();
if (windowList == null){
IJ.noImage();
return false;
}
String[] windowTitles = new String[windowList.length];
for(int i = 0; i < windowList.length; i++)
{
ImagePlus im = WindowManager.getImage (windowList[i]);
if (im == null)
windowTitles[i] = "untitled";
else
windowTitles[i] = im.getShortTitle();
}
GenericDialog gd = new GenericDialog("Alpha Blending");
gd.addChoice("Foreground image: ", windowTitles, windowTitles[0]);
gd. addNumericField("Alpha value [0. . 1]: " , alpha, 2);
gd.showDialog();
if (gd.wasCanceled())
return false;
else {
int fgIdx = gd.getNextChoiceIndex();
fgIm = WindowManager.getImage(windowList[fgIdx]);
alpha = gd.getNextNumber ();
return true;
}
}
}
Detector de movimiento
import ij.IJ;
import ij.ImagePlus;
import ij.WindowManager;
import ij.process.*;
import ij.gui.GenericDialog;
import java.awt.*;
import ij.plugin.filter.*;
public class Alpha_Blending implements PlugInFilter {
ImagePlus fgIm = null;
static double alpha = 0.5;
public int setup(String arg, ImagePlus img) {
return DOES_8G;
}
public void run(ImageProcessor bgIp) {
if(runDialog()){
ImageProcessor fgIp=fgIm.getProcessor().convertToByte(false);
fgIp = fgIp.duplicate();
bgIp.copyBits(fgIp, 0, 0, Blitter.DIFFERENCE);
int w=bgIp.getWidth();
int n=bgIp.getHeight();
for(int i =0; i < w;i++)
{
for(int j= 0; j < n;j++)
{
int p =bgIp.getPixel(i,j);
if (p <150){
p=0;
}else if(p>=150){
p=255;
}
bgIp.putPixel(i,j,p);
}
}
}
}
boolean runDialog(){
int[] windowList = WindowManager.getIDList();
if (windowList == null){
IJ.noImage();
return false;
}
String[] windowTitles = new String[windowList.length];
for(int i = 0; i < windowList.length; i++)
{
ImagePlus im = WindowManager.getImage (windowList[i]);
if (im == null)
windowTitles[i] = "untitled";
else
windowTitles[i] = im.getShortTitle();
}
GenericDialog gd = new GenericDialog("Alpha Blending");
gd.addChoice("Foreground image: ", windowTitles, windowTitles[0]);
gd. addNumericField("Alpha value [0. . 1]: " , alpha, 2);
gd.showDialog();
if (gd.wasCanceled())
return false;
else {
int fgIdx = gd.getNextChoiceIndex();
fgIm = WindowManager.getImage(windowList[fgIdx]);
alpha = gd.getNextNumber ();
return true;
}
}
}
import ij.ImagePlus;
import ij.WindowManager;
import ij.process.*;
import ij.gui.GenericDialog;
import java.awt.*;
import ij.plugin.filter.*;
public class Alpha_Blending implements PlugInFilter {
ImagePlus fgIm = null;
static double alpha = 0.5;
public int setup(String arg, ImagePlus img) {
return DOES_8G;
}
public void run(ImageProcessor bgIp) {
if(runDialog()){
ImageProcessor fgIp=fgIm.getProcessor().convertToByte(false);
fgIp = fgIp.duplicate();
bgIp.copyBits(fgIp, 0, 0, Blitter.DIFFERENCE);
int w=bgIp.getWidth();
int n=bgIp.getHeight();
for(int i =0; i < w;i++)
{
for(int j= 0; j < n;j++)
{
int p =bgIp.getPixel(i,j);
if (p <150){
p=0;
}else if(p>=150){
p=255;
}
bgIp.putPixel(i,j,p);
}
}
}
}
boolean runDialog(){
int[] windowList = WindowManager.getIDList();
if (windowList == null){
IJ.noImage();
return false;
}
String[] windowTitles = new String[windowList.length];
for(int i = 0; i < windowList.length; i++)
{
ImagePlus im = WindowManager.getImage (windowList[i]);
if (im == null)
windowTitles[i] = "untitled";
else
windowTitles[i] = im.getShortTitle();
}
GenericDialog gd = new GenericDialog("Alpha Blending");
gd.addChoice("Foreground image: ", windowTitles, windowTitles[0]);
gd. addNumericField("Alpha value [0. . 1]: " , alpha, 2);
gd.showDialog();
if (gd.wasCanceled())
return false;
else {
int fgIdx = gd.getNextChoiceIndex();
fgIm = WindowManager.getImage(windowList[fgIdx]);
alpha = gd.getNextNumber ();
return true;
}
}
}
miércoles, 18 de febrero de 2009
Manipulación de 2 o más Imágenes (imageJ)
import ij.ImagePlus;
import ij.WindowManager;import ij.process.*;
import ij.gui.GenericDialog;import ij.gui.*;
import ij.plugin.filter.PlugInFilterRunner;
import java.awt.*;import ij.plugin.filter.*;
public class Filtro_Control_Movimiento implements PlugInFilter
{
static double alpha = 0.5;
ImagePlus Iplus = null;
public int setup(String arg, ImagePlus imp)
{
return DOES_8G;
}
public void run(ImageProcessor ip)
{
if(runDialog())
{
ImageProcessor Ipro = Iplus.getProcessor().convertToByte(false);
Ipro = Ipro.duplicate();
Ipro.multiply(1-alpha);
Ipro.multiply(alpha);
Ipro.copyBits(Ipro, 0, 0, Blitter.ADD);
}
}
boolean runDialog()
{
int [] windowList = WindowManager.getIDList();
if (windowList == null)
{
IJ.noImage();
return false;
}
String[] windowTitles = new String[windowList.length];
for(int i=0; i {
ImagePlus im = WindowManager.getImage(windowList[i]);
if(im == null)
windowTitles[i] = "untitled";
else
windowTitles[i] = im.getShortTitle();
}
GenericDialog gd =new GenericDialog("Alpha Blending");
gd.addChoice("Foreground image:",windowTitles, windowTitles[0]); gd.addNumericField("Alpha value [0..1]:", alpha, 2);
gd.showDialog();
if(gd.wasCanceled())
return false;
else{
int fgIdx = gd.getNextChoiceIndex();
Iplus=WindowManager.getImage(windowList[fgIdx]); alpha=gd.getNextNumber();
return true;
}
}
}
import ij.WindowManager;import ij.process.*;
import ij.gui.GenericDialog;import ij.gui.*;
import ij.plugin.filter.PlugInFilterRunner;
import java.awt.*;import ij.plugin.filter.*;
public class Filtro_Control_Movimiento implements PlugInFilter
{
static double alpha = 0.5;
ImagePlus Iplus = null;
public int setup(String arg, ImagePlus imp)
{
return DOES_8G;
}
public void run(ImageProcessor ip)
{
if(runDialog())
{
ImageProcessor Ipro = Iplus.getProcessor().convertToByte(false);
Ipro = Ipro.duplicate();
Ipro.multiply(1-alpha);
Ipro.multiply(alpha);
Ipro.copyBits(Ipro, 0, 0, Blitter.ADD);
}
}
boolean runDialog()
{
int [] windowList = WindowManager.getIDList();
if (windowList == null)
{
IJ.noImage();
return false;
}
String[] windowTitles = new String[windowList.length];
for(int i=0; i
ImagePlus im = WindowManager.getImage(windowList[i]);
if(im == null)
windowTitles[i] = "untitled";
else
windowTitles[i] = im.getShortTitle();
}
GenericDialog gd =new GenericDialog("Alpha Blending");
gd.addChoice("Foreground image:",windowTitles, windowTitles[0]); gd.addNumericField("Alpha value [0..1]:", alpha, 2);
gd.showDialog();
if(gd.wasCanceled())
return false;
else{
int fgIdx = gd.getNextChoiceIndex();
Iplus=WindowManager.getImage(windowList[fgIdx]); alpha=gd.getNextNumber();
return true;
}
}
}
Filtro de Manejo de Imagenes
Manejo de Imagenes
import ij.IJ;
import ij.ImagePlus;
import ij.WindowManager;
import ij.process.*;
import ij.gui.GenericDialog;
import ij.gui.*;
import ij.plugin.filter.PlugInFilterRunner;
import java.awt.*;
import ij.plugin.filter.*;
public class Filtro_Control_Movimiento implements PlugInFilter
{
static double alpha = 0.5;
ImagePlus Iplus = null;
public int setup(String arg, ImagePlus imp)
{
return DOES_8G;
}
public void run(ImageProcessor ip)
{
if(runDialog())
{
ImageProcessor Ipro = Iplus.getProcessor().convertToByte(false);
Ipro = Ipro.duplicate();
Ipro.multiply(1-alpha);
Ipro.multiply(alpha);
Ipro.copyBits(Ipro, 0, 0, Blitter.ADD);
}
}
boolean runDialog()
{
int [] windowList = WindowManager.getIDList();
if (windowList == null)
{
IJ.noImage();
return false;
}
String[] windowTitles = new String[windowList.length];
for(int i=0; i {
ImagePlus im = WindowManager.getImage(windowList[i]);
if(im == null)
windowTitles[i] = "untitled";
else
windowTitles[i] = im.getShortTitle();
}
GenericDialog gd =new GenericDialog("Alpha Blending");
gd.addChoice("Foreground image:",windowTitles, windowTitles[0]);
gd.addNumericField("Alpha value [0..1]:", alpha, 2);
gd.showDialog();
if(gd.wasCanceled())
return false;
else{
int fgIdx = gd.getNextChoiceIndex();
Iplus=WindowManager.getImage(windowList[fgIdx]);
alpha=gd.getNextNumber();
return true;
}
}
}
import ij.IJ;
import ij.ImagePlus;
import ij.WindowManager;
import ij.process.*;
import ij.gui.GenericDialog;
import ij.gui.*;
import ij.plugin.filter.PlugInFilterRunner;
import java.awt.*;
import ij.plugin.filter.*;
public class Filtro_Control_Movimiento implements PlugInFilter
{
static double alpha = 0.5;
ImagePlus Iplus = null;
public int setup(String arg, ImagePlus imp)
{
return DOES_8G;
}
public void run(ImageProcessor ip)
{
if(runDialog())
{
ImageProcessor Ipro = Iplus.getProcessor().convertToByte(false);
Ipro = Ipro.duplicate();
Ipro.multiply(1-alpha);
Ipro.multiply(alpha);
Ipro.copyBits(Ipro, 0, 0, Blitter.ADD);
}
}
boolean runDialog()
{
int [] windowList = WindowManager.getIDList();
if (windowList == null)
{
IJ.noImage();
return false;
}
String[] windowTitles = new String[windowList.length];
for(int i=0; i
ImagePlus im = WindowManager.getImage(windowList[i]);
if(im == null)
windowTitles[i] = "untitled";
else
windowTitles[i] = im.getShortTitle();
}
GenericDialog gd =new GenericDialog("Alpha Blending");
gd.addChoice("Foreground image:",windowTitles, windowTitles[0]);
gd.addNumericField("Alpha value [0..1]:", alpha, 2);
gd.showDialog();
if(gd.wasCanceled())
return false;
else{
int fgIdx = gd.getNextChoiceIndex();
Iplus=WindowManager.getImage(windowList[fgIdx]);
alpha=gd.getNextNumber();
return true;
}
}
}
Manipulación de varias imágenes con image j
import ij.IJ;
import ij.ImagePlus;
import ij.WindowManager;
import ij.process.*;
import ij.gui.GenericDialog;
import java.awt.*;
import ij.plugin.filter.*;
public class Alpha_Blending implements PlugInFilter {
ImagePlus fgIm = null;
static double alpha = 0.5;
public int setup(String arg, ImagePlus img) {
return DOES_8G;
}
public void run(ImageProcessor bgIp) {
if(runDialog()){
ImageProcessor fgIp=fgIm.getProcessor().convertToByte(false);
fgIp = fgIp.duplicate();
fgIp.multiply(1-alpha);
bgIp.multiply(alpha);
bgIp.copyBits(fgIp, 0, 0, Blitter.ADD);
}
}
boolean runDialog(){
int[] windowList = WindowManager.getIDList();
if (windowList == null){
IJ.noImage();
return false;
}
String[] windowTitles = new String[windowList.length];
for(int i = 0; i < windowList.length; i++)
{
ImagePlus im = WindowManager.getImage (windowList[i]);
if (im == null)
windowTitles[i] = "untitled";
else
windowTitles[i] = im.getShortTitle();
}
GenericDialog gd = new GenericDialog("Alpha Blending");
gd.addChoice("Foreground image: ", windowTitles, windowTitles[0]);
gd. addNumericField("Alpha value [0. . 1]: " , alpha, 2);
gd.showDialog();
if (gd.wasCanceled())
return false;
else {
int fgIdx = gd.getNextChoiceIndex();
fgIm = WindowManager.getImage(windowList[fgIdx]);
alpha = gd.getNextNumber ();
return true;
}
}
}
import ij.ImagePlus;
import ij.WindowManager;
import ij.process.*;
import ij.gui.GenericDialog;
import java.awt.*;
import ij.plugin.filter.*;
public class Alpha_Blending implements PlugInFilter {
ImagePlus fgIm = null;
static double alpha = 0.5;
public int setup(String arg, ImagePlus img) {
return DOES_8G;
}
public void run(ImageProcessor bgIp) {
if(runDialog()){
ImageProcessor fgIp=fgIm.getProcessor().convertToByte(false);
fgIp = fgIp.duplicate();
fgIp.multiply(1-alpha);
bgIp.multiply(alpha);
bgIp.copyBits(fgIp, 0, 0, Blitter.ADD);
}
}
boolean runDialog(){
int[] windowList = WindowManager.getIDList();
if (windowList == null){
IJ.noImage();
return false;
}
String[] windowTitles = new String[windowList.length];
for(int i = 0; i < windowList.length; i++)
{
ImagePlus im = WindowManager.getImage (windowList[i]);
if (im == null)
windowTitles[i] = "untitled";
else
windowTitles[i] = im.getShortTitle();
}
GenericDialog gd = new GenericDialog("Alpha Blending");
gd.addChoice("Foreground image: ", windowTitles, windowTitles[0]);
gd. addNumericField("Alpha value [0. . 1]: " , alpha, 2);
gd.showDialog();
if (gd.wasCanceled())
return false;
else {
int fgIdx = gd.getNextChoiceIndex();
fgIm = WindowManager.getImage(windowList[fgIdx]);
alpha = gd.getNextNumber ();
return true;
}
}
}
Suscribirse a:
Entradas (Atom)