001/* 002 * Copyright 2010, 2011 Institut Pasteur. 003 * 004 * This file is part of ICY. 005 * 006 * ICY is free software: you can redistribute it and/or modify 007 * it under the terms of the GNU General Public License as published by 008 * the Free Software Foundation, either version 3 of the License, or 009 * (at your option) any later version. 010 * 011 * ICY is distributed in the hope that it will be useful, 012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 014 * GNU General Public License for more details. 015 * 016 * You should have received a copy of the GNU General Public License 017 * along with ICY. If not, see <http://www.gnu.org/licenses/>. 018 */ 019package plugins.tutorial.basics; 020 021import icy.image.IcyBufferedImage; 022import icy.plugin.abstract_.PluginActionable; 023import icy.sequence.Sequence; 024import icy.type.DataType; 025 026/** 027 * This plugin generates image of all types supported by ICY. 028 * 029 * @author Stephane Dallongeville 030 * @author Fabrice de Chaumont 031 */ 032 033public class GenerateImageOfDifferentType extends PluginActionable 034{ 035 @Override 036 public void run() 037 { 038 // generate a FLOAT image ( 1 channel ) 039 { 040 // create the image object with the specified 041 // width, height, number of channel (sometime called component or band) and data type 042 IcyBufferedImage image = new IcyBufferedImage(256, 256, 1, DataType.FLOAT); 043 044 // get a direct reference to first component data 045 float[] dataBuffer = image.getDataXYAsFloat(0); 046 047 // fill data 048 for (int x = 0; x < 256; x++) 049 for (int y = 0; y < 256; y++) 050 // directly assign to buffer 051 dataBuffer[x + y * 256] = (float) (Math.random() - 0.5); 052 053 // notify to icy that data has changed to refresh internal state and display 054 image.dataChanged(); 055 056 // create a sequence from the generated image 057 Sequence sequence = new Sequence("Float Image", image); 058 059 // add a "viewer" to see the sequence in the application 060 addSequence(sequence); 061 } 062 063 // generate a UNSIGNED BYTE image ( 1 channel ) 064 { 065 // create the image object with the specified 066 // width, height, number of channel (sometime called component or band) and data type 067 IcyBufferedImage image = new IcyBufferedImage(256, 256, 1, DataType.UBYTE); 068 069 // get a direct reference to first component data 070 byte[] dataBuffer = image.getDataXYAsByte(0); 071 072 // fill data 073 for (int x = 0; x < 256; x++) 074 for (int y = 0; y < 256; y++) 075 // directly assign to buffer 076 dataBuffer[x + y * 256] = (byte) (x * y); 077 078 // notify to icy that data has changed to refresh internal state and display 079 image.dataChanged(); 080 081 // create a sequence from the generated image 082 Sequence sequence = new Sequence("Unsigned byte Image", image); 083 084 // add a "viewer" to see the sequence in the application 085 addSequence(sequence); 086 } 087 088 // generate a (signed) INT image ( 1 channel ) 089 { 090 // create the image object with the specified 091 // width, height, number of channel (sometime called component or band) and data type 092 IcyBufferedImage image = new IcyBufferedImage(256, 256, 1, DataType.INT); 093 094 // get a direct reference to first component data 095 int[] dataBuffer = image.getDataXYAsInt(0); 096 097 // fill data 098 for (int x = 0; x < 256; x++) 099 for (int y = 0; y < 256; y++) 100 // directly assign to buffer 101 dataBuffer[x + y * 256] = x * y; 102 103 // notify to icy that data has changed to refresh internal state and display 104 image.dataChanged(); 105 106 // create a sequence from the generated image 107 Sequence sequence = new Sequence("Int Image", image); 108 109 // add a "viewer" to see the sequence in the application 110 addSequence(sequence); 111 } 112 113 // generate a UNISIGNED SHORT image ( 1 channel ) 114 { 115 // create the image object with the specified 116 // width, height, number of channel (sometime called component or band) and data type 117 IcyBufferedImage image = new IcyBufferedImage(256, 256, 1, DataType.USHORT); 118 119 // get a direct reference to first component data 120 short[] dataBuffer = image.getDataXYAsShort(0); 121 122 // fill data 123 for (int x = 0; x < 256; x++) 124 for (int y = 0; y < 256; y++) 125 // directly assign to buffer 126 dataBuffer[x + y * 256] = (short) (x * y); 127 128 // notify to icy that data has changed to refresh internal state and display 129 image.dataChanged(); 130 131 // create a sequence from the generated image 132 Sequence sequence = new Sequence("Unsigned Short Image", image); 133 134 // add a "viewer" to see the sequence in the application 135 addSequence(sequence); 136 } 137 138 // generate a (signed) SHORT image ( 1 channel ) 139 { 140 // create the image object with the specified 141 // width, height, number of channel (sometime called component or band) and data type 142 IcyBufferedImage image = new IcyBufferedImage(256, 256, 1, DataType.SHORT); 143 144 // get a direct reference to first component data 145 short[] dataBuffer = image.getDataXYAsShort(0); 146 147 // fill data 148 for (int x = 0; x < 256; x++) 149 for (int y = 0; y < 256; y++) 150 // directly assign to buffer 151 dataBuffer[x + y * 256] = (short) (x * y); 152 153 // notify to icy that data has changed to refresh internal state and display 154 image.dataChanged(); 155 156 // create a sequence from the generated image 157 Sequence sequence = new Sequence("Short Image", image); 158 159 // add a "viewer" to see the sequence in the application 160 addSequence(sequence); 161 } 162 163 // generate a DOUBLE image ( 1 channel ) 164 { 165 // create the image object with the specified 166 // width, height, number of channel (sometime called component or band) and data type 167 IcyBufferedImage image = new IcyBufferedImage(256, 256, 1, DataType.DOUBLE); 168 169 // get a direct reference to first component data 170 double[] dataBuffer = image.getDataXYAsDouble(0); 171 172 // fill data 173 for (int x = 0; x < 256; x++) 174 for (int y = 0; y < 256; y++) 175 // directly assign to buffer 176 dataBuffer[x + y * 256] = (Math.random() - 0.5); 177 178 // notify to icy that data has changed to refresh internal state and display 179 image.dataChanged(); 180 181 // create a sequence from the generated image 182 Sequence sequence = new Sequence("Double Image", image); 183 184 // add a "viewer" to see the sequence in the application 185 addSequence(sequence); 186 } 187 } 188 189}