├── .gitignore ├── DYimageFX-jar ├── DYimageFX-1.0.140514.jar └── ReadMe.txt ├── DYimageFX-javadoc ├── DYimageFX-javadoc-1.0.140514.zip └── ReadMe.txt ├── DYimageFX-project ├── build.xml ├── manifest.mf ├── nbproject │ ├── build-impl.xml │ ├── genfiles.properties │ ├── private │ │ └── private.properties │ ├── project.properties │ └── project.xml └── src │ └── dyimagefx │ ├── DYCanvas.java │ ├── DYColor.java │ ├── DYMosaic.java │ ├── DYimageFX.java │ ├── ImageFX.java │ ├── Intensity.java │ ├── IntensityFreq.java │ ├── Mask.java │ ├── MyImage.java │ ├── PixMath.java │ ├── Threshold.java │ ├── detect │ └── Detect.java │ ├── filter │ ├── Mean.java │ ├── Median.java │ └── Spatial.java │ ├── math │ ├── Add.java │ ├── Blend.java │ ├── Divide.java │ ├── LogicalAND.java │ ├── LogicalNAND.java │ ├── LogicalNOR.java │ ├── LogicalOR.java │ ├── LogicalXNOR.java │ ├── LogicalXOR.java │ ├── Multiply.java │ └── Subtract.java │ └── morph │ ├── Closing.java │ ├── CornerPoints.java │ ├── Dilation.java │ ├── Erosion.java │ ├── HitMiss.java │ ├── Opening.java │ ├── Skeletonization.java │ └── Thinning.java ├── LICENSE ├── README.md ├── example ├── BlueImage.java ├── Grayscale.java ├── GreenImage.java ├── MirrorImage.java ├── MyImage.java ├── Negative.java ├── RandomImage.java ├── ReadWriteImage.java ├── RedImage.java └── Sepia.java ├── src ├── imageFX │ ├── CornerPoints.java │ ├── DYCanvas.java │ ├── DYColor.java │ ├── DYMosaic.java │ ├── Detect.java │ ├── FilterImage.java │ ├── ImageFX.java │ ├── Intensity.java │ ├── IntensityFreq.java │ ├── Mask.java │ ├── MyImage.java │ ├── Threshold.java │ ├── ThresholdImage.java │ ├── filter │ │ ├── Mean.java │ │ ├── Median.java │ │ └── Spatial.java │ ├── math │ │ ├── Add.java │ │ ├── Blend.java │ │ ├── Divide.java │ │ ├── LogicalAND.java │ │ ├── LogicalNAND.java │ │ ├── LogicalNOR.java │ │ ├── LogicalOR.java │ │ ├── LogicalXNOR.java │ │ ├── LogicalXOR.java │ │ ├── Multiply.java │ │ └── Subtract.java │ └── morph │ │ ├── Closing.java │ │ ├── Dilation.java │ │ ├── Erosion.java │ │ ├── HitMiss.java │ │ ├── Opening.java │ │ ├── Skeletonization.java │ │ └── Thinning.java └── mypackage │ └── ImageProject.java └── test-image ├── test1.png ├── test2.png ├── test3.png ├── test4.png ├── test5.png ├── test6.png ├── test7.png └── test8.png /.gitignore: -------------------------------------------------------------------------------- 1 | ################# 2 | ## Eclipse 3 | ################# 4 | 5 | *.pydevproject 6 | .project 7 | .metadata 8 | bin/ 9 | tmp/ 10 | *.tmp 11 | *.bak 12 | *.swp 13 | *~.nib 14 | local.properties 15 | .classpath 16 | .settings/ 17 | .loadpath 18 | 19 | # External tool builders 20 | .externalToolBuilders/ 21 | 22 | # Locally stored "Eclipse launch configurations" 23 | *.launch 24 | 25 | # CDT-specific 26 | .cproject 27 | 28 | # PDT-specific 29 | .buildpath 30 | 31 | 32 | ################# 33 | ## Visual Studio 34 | ################# 35 | 36 | ## Ignore Visual Studio temporary files, build results, and 37 | ## files generated by popular Visual Studio add-ons. 38 | 39 | # User-specific files 40 | *.suo 41 | *.user 42 | *.sln.docstates 43 | 44 | # Build results 45 | 46 | [Dd]ebug/ 47 | [Rr]elease/ 48 | x64/ 49 | build/ 50 | [Bb]in/ 51 | [Oo]bj/ 52 | 53 | # MSTest test Results 54 | [Tt]est[Rr]esult*/ 55 | [Bb]uild[Ll]og.* 56 | 57 | *_i.c 58 | *_p.c 59 | *.ilk 60 | *.meta 61 | *.obj 62 | *.pch 63 | *.pdb 64 | *.pgc 65 | *.pgd 66 | *.rsp 67 | *.sbr 68 | *.tlb 69 | *.tli 70 | *.tlh 71 | *.tmp 72 | *.tmp_proj 73 | *.log 74 | *.vspscc 75 | *.vssscc 76 | .builds 77 | *.pidb 78 | *.log 79 | *.scc 80 | 81 | # Visual C++ cache files 82 | ipch/ 83 | *.aps 84 | *.ncb 85 | *.opensdf 86 | *.sdf 87 | *.cachefile 88 | 89 | # Visual Studio profiler 90 | *.psess 91 | *.vsp 92 | *.vspx 93 | 94 | # Guidance Automation Toolkit 95 | *.gpState 96 | 97 | # ReSharper is a .NET coding add-in 98 | _ReSharper*/ 99 | *.[Rr]e[Ss]harper 100 | 101 | # TeamCity is a build add-in 102 | _TeamCity* 103 | 104 | # DotCover is a Code Coverage Tool 105 | *.dotCover 106 | 107 | # NCrunch 108 | *.ncrunch* 109 | .*crunch*.local.xml 110 | 111 | # Installshield output folder 112 | [Ee]xpress/ 113 | 114 | # DocProject is a documentation generator add-in 115 | DocProject/buildhelp/ 116 | DocProject/Help/*.HxT 117 | DocProject/Help/*.HxC 118 | DocProject/Help/*.hhc 119 | DocProject/Help/*.hhk 120 | DocProject/Help/*.hhp 121 | DocProject/Help/Html2 122 | DocProject/Help/html 123 | 124 | # Click-Once directory 125 | publish/ 126 | 127 | # Publish Web Output 128 | *.Publish.xml 129 | *.pubxml 130 | 131 | # NuGet Packages Directory 132 | ## TODO: If you have NuGet Package Restore enabled, uncomment the next line 133 | #packages/ 134 | 135 | # Windows Azure Build Output 136 | csx 137 | *.build.csdef 138 | 139 | # Windows Store app package directory 140 | AppPackages/ 141 | 142 | # Others 143 | sql/ 144 | *.Cache 145 | ClientBin/ 146 | [Ss]tyle[Cc]op.* 147 | ~$* 148 | *~ 149 | *.dbmdl 150 | *.[Pp]ublish.xml 151 | *.pfx 152 | *.publishsettings 153 | 154 | # RIA/Silverlight projects 155 | Generated_Code/ 156 | 157 | # Backup & report files from converting an old project file to a newer 158 | # Visual Studio version. Backup files are not needed, because we have git ;-) 159 | _UpgradeReport_Files/ 160 | Backup*/ 161 | UpgradeLog*.XML 162 | UpgradeLog*.htm 163 | 164 | # SQL Server files 165 | App_Data/*.mdf 166 | App_Data/*.ldf 167 | 168 | ############# 169 | ## Windows detritus 170 | ############# 171 | 172 | # Windows image file caches 173 | Thumbs.db 174 | ehthumbs.db 175 | 176 | # Folder config file 177 | Desktop.ini 178 | 179 | # Recycle Bin used on file shares 180 | $RECYCLE.BIN/ 181 | 182 | # Mac crap 183 | .DS_Store 184 | 185 | 186 | ############# 187 | ## Python 188 | ############# 189 | 190 | *.py[co] 191 | 192 | # Packages 193 | *.egg 194 | *.egg-info 195 | dist/ 196 | build/ 197 | eggs/ 198 | parts/ 199 | var/ 200 | sdist/ 201 | develop-eggs/ 202 | .installed.cfg 203 | 204 | # Installer logs 205 | pip-log.txt 206 | 207 | # Unit test / coverage reports 208 | .coverage 209 | .tox 210 | 211 | #Translations 212 | *.mo 213 | 214 | #Mr Developer 215 | .mr.developer.cfg 216 | -------------------------------------------------------------------------------- /DYimageFX-jar/DYimageFX-1.0.140514.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yusufshakeel/Java-Image-Processing-Project/da1ff27b3c69dc5d17a1570bb712c0217f712448/DYimageFX-jar/DYimageFX-1.0.140514.jar -------------------------------------------------------------------------------- /DYimageFX-jar/ReadMe.txt: -------------------------------------------------------------------------------- 1 | DYimageFX-.jar file 2 | 3 | 4 | How to use the jar file in your project? 5 | ----------------------------------------- 6 | 1. Download the DYimageFX-.jar file. 7 | 2. Add the jar file in the class path of your IDE [NetBeans, JCreator etc] 8 | 3. Write import dyimagefx.*; to import the classes and packages. 9 | 10 | 11 | For instance, if you want to import the dyimagefx classes inside your Test.java file, then write the following line 12 | 13 | import dyimagefx.*; 14 | 15 | inside your Test.java file. 16 | 17 | So your Test.java file may look something like this 18 | 19 | import java.io.*; 20 | 21 | import dyimagefx.*; 22 | 23 | public class Test{ 24 | 25 | //your code goes here... 26 | 27 | }//class Test ends here 28 | 29 | 30 | For more details check the project wiki 31 | https://github.com/yusufshakeel/Java-Image-Processing-Project/wiki 32 | 33 | 34 | License 35 | ---------------------- 36 | The MIT License (MIT) 37 | 38 | Copyright (c) 2014 Yusuf Shakeel 39 | 40 | Permission is hereby granted, free of charge, to any person obtaining a copy of 41 | this software and associated documentation files (the "Software"), to deal in 42 | the Software without restriction, including without limitation the rights to 43 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 44 | the Software, and to permit persons to whom the Software is furnished to do so, 45 | subject to the following conditions: 46 | 47 | The above copyright notice and this permission notice shall be included in all 48 | copies or substantial portions of the Software. 49 | 50 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 51 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 52 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 53 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 54 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 55 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 56 | -------------------------------------------------------------------------------- /DYimageFX-javadoc/DYimageFX-javadoc-1.0.140514.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yusufshakeel/Java-Image-Processing-Project/da1ff27b3c69dc5d17a1570bb712c0217f712448/DYimageFX-javadoc/DYimageFX-javadoc-1.0.140514.zip -------------------------------------------------------------------------------- /DYimageFX-javadoc/ReadMe.txt: -------------------------------------------------------------------------------- 1 | DYimageFX-javadoc-.zip file 2 | 3 | The zip file contains the javadoc of the project. 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | License 13 | --------------------- 14 | The MIT License (MIT) 15 | 16 | Copyright (c) 2014 Yusuf Shakeel 17 | 18 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 19 | 20 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 21 | 22 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /DYimageFX-project/build.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | Builds, tests, and runs the project DYimageFX. 12 | 13 | 73 | 74 | -------------------------------------------------------------------------------- /DYimageFX-project/manifest.mf: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | X-COMMENT: Main-Class will be added automatically by build 3 | 4 | -------------------------------------------------------------------------------- /DYimageFX-project/nbproject/genfiles.properties: -------------------------------------------------------------------------------- 1 | build.xml.data.CRC32=a660033b 2 | build.xml.script.CRC32=80fe863b 3 | build.xml.stylesheet.CRC32=8064a381@1.74.1.48 4 | # This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. 5 | # Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. 6 | nbproject/build-impl.xml.data.CRC32=a660033b 7 | nbproject/build-impl.xml.script.CRC32=5c420d58 8 | nbproject/build-impl.xml.stylesheet.CRC32=876e7a8f@1.74.1.48 9 | -------------------------------------------------------------------------------- /DYimageFX-project/nbproject/private/private.properties: -------------------------------------------------------------------------------- 1 | compile.on.save=true 2 | user.properties.file=C:\\Users\\DY\\AppData\\Roaming\\NetBeans\\8.0\\build.properties 3 | -------------------------------------------------------------------------------- /DYimageFX-project/nbproject/project.properties: -------------------------------------------------------------------------------- 1 | annotation.processing.enabled=true 2 | annotation.processing.enabled.in.editor=false 3 | annotation.processing.processor.options= 4 | annotation.processing.processors.list= 5 | annotation.processing.run.all.processors=true 6 | annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output 7 | build.classes.dir=${build.dir}/classes 8 | build.classes.excludes=**/*.java,**/*.form 9 | # This directory is removed when the project is cleaned: 10 | build.dir=build 11 | build.generated.dir=${build.dir}/generated 12 | build.generated.sources.dir=${build.dir}/generated-sources 13 | # Only compile against the classpath explicitly listed here: 14 | build.sysclasspath=ignore 15 | build.test.classes.dir=${build.dir}/test/classes 16 | build.test.results.dir=${build.dir}/test/results 17 | # Uncomment to specify the preferred debugger connection transport: 18 | #debug.transport=dt_socket 19 | debug.classpath=\ 20 | ${run.classpath} 21 | debug.test.classpath=\ 22 | ${run.test.classpath} 23 | # Files in build.classes.dir which should be excluded from distribution jar 24 | dist.archive.excludes= 25 | # This directory is removed when the project is cleaned: 26 | dist.dir=dist 27 | dist.jar=${dist.dir}/DYimageFX.jar 28 | dist.javadoc.dir=${dist.dir}/javadoc 29 | excludes= 30 | includes=** 31 | jar.compress=false 32 | javac.classpath= 33 | # Space-separated list of extra javac options 34 | javac.compilerargs= 35 | javac.deprecation=false 36 | javac.processorpath=\ 37 | ${javac.classpath} 38 | javac.source=1.7 39 | javac.target=1.7 40 | javac.test.classpath=\ 41 | ${javac.classpath}:\ 42 | ${build.classes.dir} 43 | javac.test.processorpath=\ 44 | ${javac.test.classpath} 45 | javadoc.additionalparam= 46 | javadoc.author=false 47 | javadoc.encoding=${source.encoding} 48 | javadoc.noindex=false 49 | javadoc.nonavbar=false 50 | javadoc.notree=false 51 | javadoc.private=false 52 | javadoc.splitindex=true 53 | javadoc.use=true 54 | javadoc.version=false 55 | javadoc.windowtitle= 56 | main.class=dyimagefx.DYimageFX 57 | manifest.file=manifest.mf 58 | meta.inf.dir=${src.dir}/META-INF 59 | mkdist.disabled=false 60 | platform.active=default_platform 61 | run.classpath=\ 62 | ${javac.classpath}:\ 63 | ${build.classes.dir} 64 | # Space-separated list of JVM arguments used when running the project. 65 | # You may also define separate properties like run-sys-prop.name=value instead of -Dname=value. 66 | # To set system properties for unit tests define test-sys-prop.name=value: 67 | run.jvmargs= 68 | run.test.classpath=\ 69 | ${javac.test.classpath}:\ 70 | ${build.test.classes.dir} 71 | source.encoding=UTF-8 72 | src.dir=src 73 | test.src.dir=test 74 | -------------------------------------------------------------------------------- /DYimageFX-project/nbproject/project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | org.netbeans.modules.java.j2seproject 4 | 5 | 6 | DYimageFX 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /DYimageFX-project/src/dyimagefx/DYMosaic.java: -------------------------------------------------------------------------------- 1 | package dyimagefx; 2 | /** 3 | * File: DYMosaic.java 4 | * 5 | * Description: 6 | * This file contains methods to create random mosaic. 7 | * 8 | * @author Yusuf Shakeel 9 | * @version 1.0 10 | * Date: 21-02-2014 fri 11 | * 12 | * www.github.com/yusufshakeel/Java-Image-Processing-Project 13 | * 14 | * The MIT License (MIT) 15 | * Copyright (c) 2014 Yusuf Shakeel 16 | * 17 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 18 | * this software and associated documentation files (the "Software"), to deal in 19 | * the Software without restriction, including without limitation the rights to 20 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 21 | * the Software, and to permit persons to whom the Software is furnished to do so, 22 | * subject to the following conditions 23 | * 24 | * The above copyright notice and this permission notice shall be included in all 25 | * copies or substantial portions of the Software. 26 | * 27 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 28 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 29 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 30 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 31 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 32 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 33 | */ 34 | public class DYMosaic { 35 | 36 | //////////////////////////////// MOSAIC Method ///////////////////////////// 37 | 38 | /** 39 | * This will create the mosaic. 40 | * 41 | * @param img The image object. 42 | * @param DYColor The hex color code. 43 | * @param mSize the mosaic piece size. 44 | */ 45 | private static void _createMosaic(MyImage img, int DYColor, int mSize){ 46 | int r = (DYColor>>16)&0xFF; 47 | int g = (DYColor>>8)&0xFF; 48 | int b = DYColor&0xFF; 49 | 50 | int buff = 20; 51 | int lim = Math.max(Math.max(r, g), b); 52 | lim = (((255-lim)/2)>buff)?buff:((255-lim)/2); 53 | 54 | //image dimension 55 | int width = img.getImageWidth(); 56 | int height = img.getImageHeight(); 57 | 58 | for(int y = 0; y < height; y += mSize){ 59 | for(int x = 0; x < width; x += mSize){ 60 | int c; 61 | if(lim>0){ 62 | c = (int)(Math.random()*lim); 63 | c = ((int)(Math.random()*2))==0?c:-1*c; 64 | }else{ 65 | lim = buff; 66 | c = -1*(int)(Math.random()*lim); 67 | } 68 | 69 | int[] rgb = new int[3]; 70 | rgb[0] = (c+r)>0?(c+r):r; 71 | rgb[1] = (c+g)>0?(c+g):g; 72 | rgb[2] = (c+b)>0?(c+b):b; 73 | 74 | for(int yi = 0; yi < mSize && y+yi < height; yi++){ 75 | for(int xi = 0; xi < mSize && x+xi < width; xi++){ 76 | img.setPixel(x+xi, y+yi, 255, rgb[0], rgb[1], rgb[2]); 77 | } 78 | } 79 | } 80 | } 81 | } 82 | 83 | /** 84 | * This method will generate a random mosaic pattern. 85 | * 86 | * @param img The image object. 87 | * @param DYColor The Hex color code. 88 | * @param pieceSize The piece size. [Mosaic pieces will be in square shape] 89 | */ 90 | public static void random(MyImage img, int DYColor, int pieceSize){ 91 | int r = (int)(Math.random()*256); 92 | int g = (int)(Math.random()*256); 93 | int b = (int)(Math.random()*256); 94 | int color = (255<<24) | (r<<16) | (g<<8) | b; 95 | _createMosaic(img, color, pieceSize); 96 | } 97 | 98 | /** 99 | * This method will generate a color mosaic pattern. 100 | * 101 | * @param img The image object. 102 | * @param DYColor The Hex color code. 103 | * @param pieceSize The piece size. [Mosaic pieces will be in square shape] 104 | */ 105 | public static void myColorMosaic(MyImage img, int DYColor, int pieceSize){ 106 | _createMosaic(img, DYColor, pieceSize); 107 | } 108 | 109 | /** 110 | * This method will generate a color mosaic pattern based on the RGB value entered. 111 | * 112 | * @param img The image object 113 | * @param r The red value [0-255]. 114 | * @param g The green value [0-255]. 115 | * @param b The blue value [0-255]. 116 | * @param pieceSize The piece size. [Mosaic pieces will be in square shape] 117 | */ 118 | public static void myRGBMosaic(MyImage img, int r, int g, int b, int pieceSize){ 119 | int DYColor = (255<<24) | (r<<16) | (g<<8) | b; 120 | _createMosaic(img, DYColor, pieceSize); 121 | } 122 | }//class Mosaic ends here -------------------------------------------------------------------------------- /DYimageFX-project/src/dyimagefx/DYimageFX.java: -------------------------------------------------------------------------------- 1 | package dyimagefx; 2 | /** 3 | * File: DYimageFX.java 4 | * 5 | * Description: 6 | * Main() file 7 | * 8 | * @author Yusuf Shakeel 9 | * @version 1.0 10 | * Date: 26-01-2014 sun 11 | * 12 | * www.github.com/yusufshakeel/Java-Image-Processing-Project 13 | * 14 | * The MIT License (MIT) 15 | * Copyright (c) 2014 Yusuf Shakeel 16 | * 17 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 18 | * this software and associated documentation files (the "Software"), to deal in 19 | * the Software without restriction, including without limitation the rights to 20 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 21 | * the Software, and to permit persons to whom the Software is furnished to do so, 22 | * subject to the following conditions 23 | * 24 | * The above copyright notice and this permission notice shall be included in all 25 | * copies or substantial portions of the Software. 26 | * 27 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 28 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 29 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 30 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 31 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 32 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 33 | */ 34 | public class DYimageFX { 35 | public static void main(String[] args) { 36 | about(); 37 | System.out.println(); 38 | author(); 39 | System.out.println(); 40 | license(); 41 | } 42 | 43 | public static void about(){ 44 | String product = "DY imageFX - Open Source Image Processing Project"; 45 | String version = "Version: 1.0"; 46 | String latestUpdate = "Latest Update: 28-04-2014 Monday"; 47 | String url = "GitHub: www.github.com/yusufshakeel/Java-Image-Processing-Project"; 48 | 49 | //output 50 | System.out.println(product); 51 | System.out.println(version); 52 | System.out.println(latestUpdate); 53 | System.out.println(url); 54 | } 55 | public static void author(){ 56 | String name = "Author: Yusuf Shakeel"; 57 | String links = "Links:\n" 58 | +"GitHub: www.github.com/yusufshakeel\n" 59 | + "YouTube: www.youtube.com/yusufshakeel\n" 60 | + "Facebook: www.facebook.com/yusufshakeel\n" 61 | + "GooglePlus: plus.google.com/+YusufShakeel"; 62 | //output 63 | System.out.println(name); 64 | System.out.println(links); 65 | } 66 | 67 | public static void license(){ 68 | String license = "License:\n" 69 | +"The MIT License (MIT)\n" 70 | +"Copyright (c) 2014 Yusuf Shakeel\n" 71 | +"\n" 72 | +"Permission is hereby granted, free of charge, to any person obtaining a copy of\n" 73 | +"this software and associated documentation files (the \"Software\"), to deal in\n" 74 | +"the Software without restriction, including without limitation the rights to\n" 75 | +"use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\n" 76 | +"the Software, and to permit persons to whom the Software is furnished to do so,\n" 77 | +"subject to the following conditions\n" 78 | +"\n" 79 | +"The above copyright notice and this permission notice shall be included in all\n" 80 | +"copies or substantial portions of the Software.\n" 81 | +"\n" 82 | +"THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n" 83 | +"IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\n" 84 | +"FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\n" 85 | +"COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\n" 86 | +"IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\n" 87 | +"CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE."; 88 | System.out.println(license); 89 | } 90 | } -------------------------------------------------------------------------------- /DYimageFX-project/src/dyimagefx/Intensity.java: -------------------------------------------------------------------------------- 1 | package dyimagefx; 2 | /** 3 | * File: Intensity.java 4 | * 5 | * Description: 6 | * This will find max and min intensity of the image. 7 | * 8 | * @author Yusuf Shakeel 9 | * @version 1.0 10 | * date: 06-05-2014 tue 11 | * 12 | * www.github.com/yusufshakeel/Java-Image-Processing-Project 13 | * 14 | * The MIT License (MIT) 15 | * Copyright (c) 2014 Yusuf Shakeel 16 | * 17 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 18 | * this software and associated documentation files (the "Software"), to deal in 19 | * the Software without restriction, including without limitation the rights to 20 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 21 | * the Software, and to permit persons to whom the Software is furnished to do so, 22 | * subject to the following conditions 23 | * 24 | * The above copyright notice and this permission notice shall be included in all 25 | * copies or substantial portions of the Software. 26 | * 27 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 28 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 29 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 30 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 31 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 32 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 33 | */ 34 | public class Intensity { 35 | 36 | ///////////////////////////// GRAYSCALE IMAGE ////////////////////////////// 37 | 38 | /** 39 | * This will return the maximum intensity of the grayscale image img. 40 | * 41 | * @param img The grayscale image. 42 | * @return maximum intensity. 43 | */ 44 | public static int grayscale_getMax(MyImage img){ 45 | int maxIntensity = 0; 46 | 47 | //image dimension 48 | int width = img.getImageWidth(); 49 | int height = img.getImageHeight(); 50 | 51 | //for grayscale image RGB value is same. So considering RED value. 52 | for(int y = 0; y < height; y++){ 53 | for(int x = 0; x < width; x++){ 54 | int r = img.getRed(x, y); 55 | if(r > maxIntensity){ 56 | maxIntensity = r; 57 | } 58 | } 59 | } 60 | return maxIntensity; 61 | } 62 | 63 | /** 64 | * This will return the minimum intensity of the grayscale image img. 65 | * 66 | * @param img The grayscale image. 67 | * @return minimum intensity. 68 | */ 69 | public static int grayscale_getMin(MyImage img){ 70 | int minIntensity = 255; 71 | 72 | //image dimension 73 | int width = img.getImageWidth(); 74 | int height = img.getImageHeight(); 75 | 76 | //for grayscale image RGB value is same. So considering RED value. 77 | for(int y = 0; y < height; y++){ 78 | for(int x = 0; x < width; x++){ 79 | int r = img.getRed(x, y); 80 | if(r < minIntensity){ 81 | minIntensity = r; 82 | } 83 | } 84 | } 85 | return minIntensity; 86 | } 87 | 88 | ///////////////////////////// RED IMAGE //////////////////////////////////// 89 | 90 | /** 91 | * This will return the maximum intensity of the RED image img. 92 | * 93 | * @param img The RED image. 94 | * @return maximum intensity. 95 | */ 96 | public static int red_getMax(MyImage img){ 97 | int maxIntensity = 0; 98 | 99 | //image dimension 100 | int width = img.getImageWidth(); 101 | int height = img.getImageHeight(); 102 | 103 | for(int y = 0; y < height; y++){ 104 | for(int x = 0; x < width; x++){ 105 | int r = img.getRed(x, y); 106 | if(r > maxIntensity){ 107 | maxIntensity = r; 108 | } 109 | } 110 | } 111 | return maxIntensity; 112 | } 113 | 114 | /** 115 | * This will return the minimum intensity of the RED image img. 116 | * 117 | * @param img The RED image. 118 | * @return minimum intensity. 119 | */ 120 | public static int red_getMin(MyImage img){ 121 | int minIntensity = 255; 122 | 123 | //image dimension 124 | int width = img.getImageWidth(); 125 | int height = img.getImageHeight(); 126 | 127 | for(int y = 0; y < height; y++){ 128 | for(int x = 0; x < width; x++){ 129 | int r = img.getRed(x, y); 130 | if(r < minIntensity){ 131 | minIntensity = r; 132 | } 133 | } 134 | } 135 | return minIntensity; 136 | } 137 | 138 | ///////////////////////////// GREEN IMAGE ////////////////////////////////// 139 | 140 | /** 141 | * This will return the maximum intensity of the GREEN image img. 142 | * 143 | * @param img The GREEN image. 144 | * @return maximum intensity. 145 | */ 146 | public static int green_getMax(MyImage img){ 147 | int maxIntensity = 0; 148 | 149 | //image dimension 150 | int width = img.getImageWidth(); 151 | int height = img.getImageHeight(); 152 | 153 | for(int y = 0; y < height; y++){ 154 | for(int x = 0; x < width; x++){ 155 | int g = img.getGreen(x, y); 156 | if(g > maxIntensity){ 157 | maxIntensity = g; 158 | } 159 | } 160 | } 161 | return maxIntensity; 162 | } 163 | 164 | /** 165 | * This will return the minimum intensity of the GREEN image img. 166 | * 167 | * @param img The GREEN image. 168 | * @return minimum intensity. 169 | */ 170 | public static int green_getMin(MyImage img){ 171 | int minIntensity = 255; 172 | 173 | //image dimension 174 | int width = img.getImageWidth(); 175 | int height = img.getImageHeight(); 176 | 177 | for(int y = 0; y < height; y++){ 178 | for(int x = 0; x < width; x++){ 179 | int g = img.getGreen(x, y); 180 | if(g < minIntensity){ 181 | minIntensity = g; 182 | } 183 | } 184 | } 185 | return minIntensity; 186 | } 187 | 188 | ///////////////////////////// BLUE IMAGE /////////////////////////////////// 189 | 190 | /** 191 | * This will return the maximum intensity of the BLUE image img. 192 | * 193 | * @param img The BLUE image. 194 | * @return maximum intensity. 195 | */ 196 | public static int blue_getMax(MyImage img){ 197 | int maxIntensity = 0; 198 | 199 | //image dimension 200 | int width = img.getImageWidth(); 201 | int height = img.getImageHeight(); 202 | 203 | for(int y = 0; y < height; y++){ 204 | for(int x = 0; x < width; x++){ 205 | int b = img.getBlue(x, y); 206 | if(b > maxIntensity){ 207 | maxIntensity = b; 208 | } 209 | } 210 | } 211 | return maxIntensity; 212 | } 213 | 214 | /** 215 | * This will return the minimum intensity of the BLUE image img. 216 | * 217 | * @param img The BLUE image. 218 | * @return minimum intensity. 219 | */ 220 | public static int blue_getMin(MyImage img){ 221 | int minIntensity = 255; 222 | 223 | //image dimension 224 | int width = img.getImageWidth(); 225 | int height = img.getImageHeight(); 226 | 227 | for(int y = 0; y < height; y++){ 228 | for(int x = 0; x < width; x++){ 229 | int b = img.getBlue(x, y); 230 | if(b < minIntensity){ 231 | minIntensity = b; 232 | } 233 | } 234 | } 235 | return minIntensity; 236 | } 237 | 238 | ///////////////////////////// COLOR IMAGE ////////////////////////////////// 239 | 240 | /** 241 | * This will return the maximum intensity of the color image img. 242 | * 243 | * @param img The color image. 244 | * @return maximum intensity array having 3 elements for RGB. 245 | */ 246 | public static int[] color_getMax(MyImage img){ 247 | int maxIntensity[] = new int[3]; 248 | maxIntensity[0] = red_getMax(img); 249 | maxIntensity[1] = green_getMax(img); 250 | maxIntensity[2] = blue_getMax(img); 251 | return maxIntensity; 252 | } 253 | 254 | /** 255 | * This will return the minimum intensity of the color image img. 256 | * 257 | * @param img The color image. 258 | * @return minimum intensity. 259 | */ 260 | public static int[] color_getMin(MyImage img){ 261 | int minIntensity[] = new int[3]; 262 | minIntensity[0] = red_getMin(img); 263 | minIntensity[1] = green_getMin(img); 264 | minIntensity[2] = blue_getMin(img); 265 | return minIntensity; 266 | } 267 | }//class ends here 268 | -------------------------------------------------------------------------------- /DYimageFX-project/src/dyimagefx/Mask.java: -------------------------------------------------------------------------------- 1 | package dyimagefx; 2 | /** 3 | * File: Mask.java 4 | * 5 | * Description: 6 | * This fill will create mask aka kernel or structuring element. 7 | * 8 | * @author Yusuf Shakeel 9 | * @version 1.0 10 | * date: 06-05-2014 tue 11 | * 12 | * www.github.com/yusufshakeel/Java-Image-Processing-Project 13 | * 14 | * The MIT License (MIT) 15 | * Copyright (c) 2014 Yusuf Shakeel 16 | * 17 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 18 | * this software and associated documentation files (the "Software"), to deal in 19 | * the Software without restriction, including without limitation the rights to 20 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 21 | * the Software, and to permit persons to whom the Software is furnished to do so, 22 | * subject to the following conditions 23 | * 24 | * The above copyright notice and this permission notice shall be included in all 25 | * copies or substantial portions of the Software. 26 | * 27 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 28 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 29 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 30 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 31 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 32 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 33 | */ 34 | public class Mask { 35 | 36 | //mask array 37 | private static int mask[]; 38 | 39 | 40 | /** 41 | * This will return a square mask [maskSize x maskSize] having all the elements set to 1. 42 | * 43 | * @param maskSize the size of the 2D array 44 | * @return 2D mask 45 | */ 46 | public static int[] allOne(int maskSize){ 47 | mask = new int[maskSize*maskSize]; 48 | java.util.Arrays.fill(mask, 1); 49 | return mask; 50 | } 51 | 52 | ///////////////////////////// CIRCLE /////////////////////////////////////// 53 | 54 | /** 55 | * This will return a square mask with circumference of the circle set to 1. 56 | * 57 | * @param diameter diameter of the circle. [An odd integer like 9, 11, 13 etc] 58 | * @return 2D mask 59 | */ 60 | public static int[] drawCircle(int diameter){ 61 | int radius = diameter/2; 62 | int mask[] = new int[diameter * diameter]; 63 | int x = 0, y = radius, p = 1 - radius; 64 | int cx = diameter/2, cy = diameter/2; 65 | 66 | while(x<=y){ 67 | //draw circumference of the circle circle 68 | mask[(cx+x)+(cy+y)*diameter] = 1; 69 | mask[(cx-x)+(cy+y)*diameter] = 1; 70 | mask[(cx+x)+(cy-y)*diameter] = 1; 71 | mask[(cx-x)+(cy-y)*diameter] = 1; 72 | mask[(cx+y)+(cy+x)*diameter] = 1; 73 | mask[(cx-y)+(cy+x)*diameter] = 1; 74 | mask[(cx+y)+(cy-x)*diameter] = 1; 75 | mask[(cx-y)+(cy-x)*diameter] = 1; 76 | 77 | x++; 78 | if(p<0){ 79 | p+=2*x+1; 80 | }else{ 81 | y--; 82 | p+=2*(x-y)+1; 83 | } 84 | } 85 | return mask; 86 | } 87 | 88 | /** 89 | * This will return a square mask with circle filled with 1. 90 | * 91 | * @param diameter diameter of the circle. [An odd integer like 9, 11, 13...] 92 | * @return 2D mask 93 | */ 94 | public static int[] fillCircle(int diameter){ 95 | int radius = diameter/2; 96 | int cx = diameter/2, cy = diameter/2; 97 | 98 | //draw circle 99 | mask = drawCircle(diameter); 100 | 101 | //fill circle 102 | floodFill(diameter, diameter, cx, cy, 0, 1); 103 | 104 | return mask; 105 | } 106 | 107 | //////////////////////////////// DIAMOND /////////////////////////////////// 108 | 109 | /** 110 | * This will return a square mask having diamond shape set to 1. 111 | * 112 | * @param width The width of the square mask. [An odd integer like 9, 11, 13 etc] 113 | * @return 2D mask 114 | */ 115 | public static int[] drawDiamond(int width){ 116 | int mask[] = new int[width * width]; 117 | int x = 0, y = width/2; 118 | int cx = width/2, cy = width/2; 119 | 120 | while(x<=y){ 121 | //draw diamond 122 | mask[(cx+x)+(cy+y)*width] = 1; 123 | mask[(cx-x)+(cy+y)*width] = 1; 124 | mask[(cx+x)+(cy-y)*width] = 1; 125 | mask[(cx-x)+(cy-y)*width] = 1; 126 | mask[(cx+y)+(cy+x)*width] = 1; 127 | mask[(cx-y)+(cy+x)*width] = 1; 128 | mask[(cx+y)+(cy-x)*width] = 1; 129 | mask[(cx-y)+(cy-x)*width] = 1; 130 | 131 | x++; 132 | y--; 133 | } 134 | return mask; 135 | } 136 | 137 | /** 138 | * This will return a square mask with filled diamond. 139 | * 140 | * @param width The width of the square mask. [An odd integer like 9, 11, 13...] 141 | * @return 2D mask 142 | */ 143 | public static int[] fillDiamond(int width){ 144 | int cx = width/2, cy = width/2; 145 | 146 | //draw diamond 147 | mask = drawDiamond(width); 148 | 149 | //fill diamond 150 | floodFill(width, width, cx, cy, 0, 1); 151 | 152 | return mask; 153 | } 154 | 155 | /** 156 | * This will return a square mask with of diamond shape with corner filled with 1. 157 | * 158 | * @param width The width of the square mask. [An odd integer like 9, 11, 13...] 159 | * @return 2D mask 160 | */ 161 | public static int[] fillDiamondCorners(int width){ 162 | int cx = width/2, cy = width/2; 163 | 164 | //draw diamond 165 | mask = drawDiamond(width); 166 | 167 | //fill diamond 168 | floodFill(width, width, cx, cy, 0, 1); 169 | 170 | //invert 171 | for(int y = 0; y < width; y++){ 172 | for(int x = 0; x < width; x++){ 173 | mask[x+y*width] = (mask[x+y*width]==1)?0:1; 174 | } 175 | } 176 | 177 | return mask; 178 | } 179 | 180 | ///////////////////////////// FLOOD FILL /////////////////////////////////// 181 | 182 | /** 183 | * This method will floodfill the image. 184 | * 185 | * @param width the width of the image 186 | * @param height the height of the image 187 | * @param cx x coordinate of the center of the image 188 | * @param cy y coordinate of the center of the image 189 | * @param oldColor the color to be replaced 190 | * @param newColor the color that will replace the oldColor 191 | */ 192 | private static void floodFill(int width, int height, int cx, int cy, int oldColor, int newColor){ 193 | if(cx<0 || cx>=width || cy<0 || cy>=height){ 194 | return; 195 | } 196 | 197 | if(mask[cx+cy*width] == oldColor){ 198 | mask[cx+cy*width] = newColor; 199 | floodFill(width, height, cx+1, cy, oldColor, newColor); 200 | floodFill(width, height, cx, cy+1, oldColor, newColor); 201 | floodFill(width, height, cx-1, cy, oldColor, newColor); 202 | floodFill(width, height, cx, cy-1, oldColor, newColor); 203 | } 204 | } 205 | }//class ends here 206 | -------------------------------------------------------------------------------- /DYimageFX-project/src/dyimagefx/detect/Detect.java: -------------------------------------------------------------------------------- 1 | package dyimagefx.detect; 2 | import dyimagefx.MyImage; 3 | /** 4 | * File: Detect.java 5 | * 6 | * Description: 7 | * This file contains edge/line detection methods. 8 | * 9 | * @author Yusuf Shakeel 10 | * @version 1.0 11 | * Date: 25-04-2014 fri 12 | * 13 | * www.github.com/yusufshakeel/Java-Image-Processing-Project 14 | * 15 | * The MIT License (MIT) 16 | * Copyright (c) 2014 Yusuf Shakeel 17 | * 18 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 19 | * this software and associated documentation files (the "Software"), to deal in 20 | * the Software without restriction, including without limitation the rights to 21 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 22 | * the Software, and to permit persons to whom the Software is furnished to do so, 23 | * subject to the following conditions 24 | * 25 | * The above copyright notice and this permission notice shall be included in all 26 | * copies or substantial portions of the Software. 27 | * 28 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 29 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 30 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 31 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 32 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 33 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 34 | */ 35 | public class Detect { 36 | 37 | //////////////////////////////// EDGE DETECT METHOD //////////////////////// 38 | 39 | /** 40 | * This method will detect edges in the image. 41 | * 42 | * @param img The image to blur. 43 | */ 44 | public static void edge(MyImage img){ 45 | 46 | /** 47 | * Mask is a 2D square of odd size like 3x3 48 | * For simplicity storing it into 1D array. 49 | */ 50 | int mask[] = new int[]{ -1, -1, -1, 51 | -1, 8, -1, 52 | -1, -1, -1}; 53 | 54 | int maskSize = 3; //The width of the mask. 55 | 56 | /** 57 | * Buffered array of pixels holds the intermediate value of pixels that 58 | * is multiplied with the mask to get the final value for the center 59 | * pixel under the mask. 60 | */ 61 | int buff[]; 62 | 63 | /** 64 | * This array will store the output of the edge detect operation which will 65 | * be later written back to the original image pixels. 66 | */ 67 | int outputPixels[] = new int[img.getImageTotalPixels()]; 68 | 69 | //image dimension 70 | int width = img.getImageWidth(); 71 | int height = img.getImageHeight(); 72 | 73 | /** edge detect operation */ 74 | for(int y = 0; y < height; y++){ 75 | for(int x = 0; x < width; x++){ 76 | /** Fill buff array */ 77 | int i = 0; 78 | buff = new int[9]; 79 | for(int r = y - (maskSize / 2); r <= y + (maskSize / 2); r++){ 80 | for(int c = x - (maskSize / 2); c <= x + (maskSize / 2); c++){ 81 | if(r < 0 || r >= height || c < 0 || c >= width){ 82 | /** Some portion of the mask is outside the image. */ 83 | int tr = r, tc = c; 84 | if(r < 0){ 85 | tr = r+1; 86 | }else if(r == height){ 87 | tr = r-1; 88 | } 89 | if(c < 0){ 90 | tc = c+1; 91 | }else if(c == width){ 92 | tc = c-1; 93 | } 94 | buff[i] = img.getPixel(tc, tr); 95 | }else{ 96 | buff[i] = img.getPixel(c, r); 97 | } 98 | i++; 99 | } 100 | } 101 | 102 | /** Multiply mask with buff array to get the final value. */ 103 | int sa=0, sr=0, sg=0, sb=0; 104 | for(i = 0; i < 9; i++){ 105 | sa += (mask[i]*dyimagefx.PixMath.getAlpha(buff[i]))/16; 106 | sr += (mask[i]*dyimagefx.PixMath.getRed(buff[i]))/16; 107 | sg += (mask[i]*dyimagefx.PixMath.getGreen(buff[i]))/16; 108 | sb += (mask[i]*dyimagefx.PixMath.getBlue(buff[i]))/16; 109 | } 110 | 111 | /** Save result in outputPixels array. */ 112 | int p = dyimagefx.PixMath.getPixel(sa, sr, sg, sb); 113 | outputPixels[x+y*width] = p; 114 | } 115 | } 116 | /** Write the output pixels to the image pixels */ 117 | for(int y = 0; y < height; y++){ 118 | for(int x = 0; x < width; x++){ 119 | img.setPixelToValue(x, y, outputPixels[x+y*width]); 120 | } 121 | } 122 | } 123 | }//class ends here -------------------------------------------------------------------------------- /DYimageFX-project/src/dyimagefx/filter/Spatial.java: -------------------------------------------------------------------------------- 1 | package dyimagefx.filter; 2 | import dyimagefx.MyImage; 3 | /** 4 | * File: Spatial.java 5 | * 6 | * Description: 7 | * This will perform spatial - conservative smoothing. 8 | * It is a noise reduction technique. 9 | * 10 | * @author Yusuf Shakeel 11 | * @version 1.0 12 | * Date: 25-04-2014 fri 13 | * 14 | * www.github.com/yusufshakeel/Java-Image-Processing-Project 15 | * 16 | * The MIT License (MIT) 17 | * Copyright (c) 2014 Yusuf Shakeel 18 | * 19 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 20 | * this software and associated documentation files (the "Software"), to deal in 21 | * the Software without restriction, including without limitation the rights to 22 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 23 | * the Software, and to permit persons to whom the Software is furnished to do so, 24 | * subject to the following conditions 25 | * 26 | * The above copyright notice and this permission notice shall be included in all 27 | * copies or substantial portions of the Software. 28 | * 29 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 30 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 31 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 32 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 33 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 34 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 35 | */ 36 | public class Spatial { 37 | 38 | /** 39 | * This method is used to perform spatial filtering on the image object passed. 40 | * Also known as Conservative smoothing and used for noise reduction. 41 | * 42 | * @param img The image object passed on which spatial filtering is performed. 43 | * @param maskSize - The size of the mask is an odd integer like 3, 5, 7 … etc. 44 | */ 45 | public static void spatialFilter_RGB(MyImage img, int maskSize){ 46 | 47 | /** 48 | * This array will store the output of the spatial filter operation which will 49 | * be later written back to the original image pixels. 50 | */ 51 | int outputPixels[] = new int[img.getImageTotalPixels()]; 52 | 53 | //image dimension 54 | int width = img.getImageWidth(); 55 | int height = img.getImageHeight(); 56 | 57 | /** 58 | * red, green and blue are a 2D square of odd size like 3x3, 5x5, 7x7, ... 59 | * For simplicity storing it into 1D array. 60 | */ 61 | int red[], green[], blue[]; 62 | 63 | /** spatial Filter operation */ 64 | for(int y = 0; y < height; y++){ 65 | for(int x = 0; x < width; x++){ 66 | red = new int[maskSize * maskSize]; 67 | green = new int [maskSize * maskSize]; 68 | blue = new int [maskSize * maskSize]; 69 | int count = 0; 70 | for(int r = y - (maskSize / 2); r <= y + (maskSize / 2); r++){ 71 | for(int c = x - (maskSize / 2); c <= x + (maskSize / 2); c++){ 72 | if(r < 0 || r >= height || c < 0 || c >= width){ 73 | /** Some portion of the mask is outside the image. */ 74 | continue; 75 | }else if(x == c && y == r){ 76 | /** pixel below the center of the mask */ 77 | continue; 78 | }else{ 79 | red[count] = img.getRed(c, r); 80 | green[count] = img.getGreen(c, r); 81 | blue[count] = img.getBlue(c, r); 82 | count++; 83 | } 84 | } 85 | } 86 | 87 | /** sort red, green, blue array */ 88 | java.util.Arrays.sort(red); 89 | java.util.Arrays.sort(green); 90 | java.util.Arrays.sort(blue); 91 | 92 | //RGB value of image pixel 93 | int pixelRED = img.getRed(x, y); 94 | int pixelGREEN = img.getGreen(x, y); 95 | int pixelBLUE = img.getBlue(x, y); 96 | 97 | //final RGB value 98 | int fRED, fGREEN, fBLUE; 99 | 100 | //compute final RGB value 101 | if(pixelRED > red[maskSize*maskSize - 1]){ 102 | fRED = red[maskSize*maskSize - 1]; 103 | }else if(pixelRED < red[maskSize*maskSize - count]){ 104 | fRED = red[maskSize*maskSize - count]; 105 | }else{ 106 | fRED = pixelRED; 107 | } 108 | 109 | if(pixelGREEN > green[maskSize*maskSize - 1]){ 110 | fGREEN = green[maskSize*maskSize - 1]; 111 | }else if(pixelGREEN < green[maskSize*maskSize - count]){ 112 | fGREEN = green[maskSize*maskSize - count]; 113 | }else{ 114 | fGREEN = pixelGREEN; 115 | } 116 | 117 | if(pixelBLUE > blue[maskSize*maskSize - 1]){ 118 | fBLUE = blue[maskSize*maskSize - 1]; 119 | }else if(pixelBLUE < blue[maskSize*maskSize - count]){ 120 | fBLUE = blue[maskSize*maskSize - count]; 121 | }else{ 122 | fBLUE = pixelBLUE; 123 | } 124 | 125 | /** save spatial value in outputPixels array */ 126 | int p = dyimagefx.PixMath.getPixel(255, fRED, fGREEN, fBLUE); 127 | outputPixels[x+y*width] = p; 128 | } 129 | } 130 | /** Write the output pixels to the image pixels */ 131 | for(int y = 0; y < height; y++){ 132 | for(int x = 0; x < width; x++){ 133 | img.setPixelToValue(x, y, outputPixels[x+y*width]); 134 | } 135 | } 136 | } 137 | }//class ends here 138 | -------------------------------------------------------------------------------- /DYimageFX-project/src/dyimagefx/math/Add.java: -------------------------------------------------------------------------------- 1 | package dyimagefx.math; 2 | import dyimagefx.MyImage; 3 | 4 | /** 5 | * File: Add.java 6 | * 7 | * Description: 8 | * To perform addition of image pixels. 9 | * 10 | * @author Yusuf Shakeel 11 | * @version 1.0 12 | * Date: 25-04-2014 fri 13 | * 14 | * www.github.com/yusufshakeel/Java-Image-Processing-Project 15 | * 16 | * The MIT License (MIT) 17 | * Copyright (c) 2014 Yusuf Shakeel 18 | * 19 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 20 | * this software and associated documentation files (the "Software"), to deal in 21 | * the Software without restriction, including without limitation the rights to 22 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 23 | * the Software, and to permit persons to whom the Software is furnished to do so, 24 | * subject to the following conditions 25 | * 26 | * The above copyright notice and this permission notice shall be included in all 27 | * copies or substantial portions of the Software. 28 | * 29 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 30 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 31 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 32 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 33 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 34 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 35 | */ 36 | public class Add { 37 | 38 | /////////////////////////////// BINARY IMAGE //////////////////////////////// 39 | 40 | /** 41 | * This method will add the pixels of the binary image. 42 | * It takes two equal size binary images and adds their pixels. 43 | * The result of addition is saved in resultImg which is also of the same size. 44 | * 45 | * @param sourceImg1 The first image. 46 | * @param sourceImg2 The second image. 47 | * @param resultImg This will hold the resultant image after addition of image1 and image2. 48 | */ 49 | public static void binaryImage(MyImage sourceImg1, MyImage sourceImg2, MyImage resultImg){ 50 | /** 51 | * Note grayscale and binary image pixel addition is almost same. 52 | * So, calling grayscaleImage() method 53 | */ 54 | grayscaleImage(sourceImg1, sourceImg2, resultImg); 55 | } 56 | 57 | /** 58 | * This method will add the pixels of the binary image. 59 | * It takes a binary images and adds its pixel with a constant value C. 60 | * The result of addition is saved in resultImg which is of same size as sourceImage. 61 | * 62 | * @param sourceImg1 The first image. 63 | * @param C The constant to add. [0-255] 64 | * @param resultImg This will hold the resultant image after addition of image1 and image2. 65 | */ 66 | public static void binaryImage(MyImage sourceImg1, int C, MyImage resultImg){ 67 | /** 68 | * Note grayscale and binary image pixel addition is almost same. 69 | * So, calling grayscaleImage() method 70 | */ 71 | grayscaleImage(sourceImg1, C, resultImg); 72 | } 73 | 74 | /////////////////////////////// GRAYSCALE IMAGE //////////////////////////// 75 | 76 | /** 77 | * This method will add the pixels of the grayscale image. 78 | * It takes two equal size grayscale images and adds their pixels. 79 | * The result of addition is saved in resultImg which is also of the same size. 80 | * 81 | * @param sourceImg1 The first image. 82 | * @param sourceImg2 The second image. 83 | * @param resultImg This will hold the resultant image after addition of image1 and image2. 84 | */ 85 | public static void grayscaleImage(MyImage sourceImg1, MyImage sourceImg2, MyImage resultImg){ 86 | 87 | //image dimension - common for all the three images 88 | int width = sourceImg1.getImageWidth(); 89 | int height = sourceImg1.getImageHeight(); 90 | 91 | //variable 92 | int p, result; 93 | 94 | /** 95 | * Add pixels 96 | * Grayscale image will have same value for RGB so take any one component. 97 | */ 98 | for(int y = 0; y < height; y++){ 99 | for(int x = 0; x < width; x++){ 100 | p = sourceImg1.getBlue(x, y) + sourceImg2.getBlue(x, y); 101 | result = (p>255)?255:p; 102 | resultImg.setPixel(x, y, 255, result, result, result); 103 | } 104 | } 105 | } 106 | 107 | /** 108 | * This method will add the pixels of the grayscale image. 109 | * It takes a grayscale images and adds its pixel with a constant value C. 110 | * The result of addition is saved in resultImg which is of the size of sourceImage. 111 | * 112 | * @param sourceImg1 The first image. 113 | * @param C constant number to add. [0-255] 114 | * @param resultImg This will hold the resultant image after addition of image1 and image2. 115 | */ 116 | public static void grayscaleImage(MyImage sourceImg1, int C, MyImage resultImg){ 117 | 118 | //image dimension - common for the two images 119 | int width = sourceImg1.getImageWidth(); 120 | int height = sourceImg1.getImageHeight(); 121 | 122 | //variable 123 | int p, result; 124 | 125 | /** 126 | * Add pixels 127 | * Grayscale image will have same value for RGB so take any one component. 128 | */ 129 | for(int y = 0; y < height; y++){ 130 | for(int x = 0; x < width; x++){ 131 | p = sourceImg1.getBlue(x, y) + C; 132 | result = (p>255)?255:p; 133 | resultImg.setPixel(x, y, 255, result, result, result); 134 | } 135 | } 136 | } 137 | 138 | /////////////////////////////// COLOR IMAGE //////////////////////////////// 139 | 140 | /** 141 | * This method will add the pixels of the color image. 142 | * It takes two equal size color images and adds their pixels. 143 | * The result of addition is saved in resultImg which is also of the same size. 144 | * 145 | * @param sourceImg1 The first image. 146 | * @param sourceImg2 The second image. 147 | * @param resultImg This will hold the resultant image after addition of image1 and image2. 148 | */ 149 | public static void colorImage(MyImage sourceImg1, MyImage sourceImg2, MyImage resultImg){ 150 | 151 | //image dimension - common for all the three images 152 | int width = sourceImg1.getImageWidth(); 153 | int height = sourceImg1.getImageHeight(); 154 | 155 | //variable 156 | int pRED, pGREEN, pBLUE, rRED, rGREEN, rBLUE; 157 | 158 | /** 159 | * Add pixels 160 | */ 161 | for(int y = 0; y < height; y++){ 162 | for(int x = 0; x < width; x++){ 163 | //add the RGB components of the two source image 164 | pRED = sourceImg1.getRed(x, y) + sourceImg2.getRed(x, y); 165 | pGREEN = sourceImg1.getGreen(x, y) + sourceImg2.getGreen(x, y); 166 | pBLUE = sourceImg1.getBlue(x, y) + sourceImg2.getBlue(x, y); 167 | 168 | //find result 169 | rRED = (pRED>255)?255:pRED; 170 | rGREEN = (pGREEN>255)?255:pGREEN; 171 | rBLUE = (pBLUE>255)?255:pBLUE; 172 | 173 | //save result 174 | resultImg.setPixel(x, y, 255, rRED, rGREEN, rBLUE); 175 | } 176 | } 177 | } 178 | 179 | /** 180 | * This method will add the pixels of the color image. 181 | * It takes a color images and adds its pixel with a constant value C. 182 | * The result of addition is saved in resultImg which is of the size of sourceImage. 183 | * 184 | * @param sourceImg1 The first image. 185 | * @param C The constant value to add. [0-255] 186 | * @param resultImg This will hold the resultant image after addition of image1 and image2. 187 | */ 188 | public static void colorImage(MyImage sourceImg1, int C, MyImage resultImg){ 189 | 190 | //image dimension - common for all the three images 191 | int width = sourceImg1.getImageWidth(); 192 | int height = sourceImg1.getImageHeight(); 193 | 194 | //variable 195 | int pRED, pGREEN, pBLUE, rRED, rGREEN, rBLUE; 196 | 197 | /** 198 | * Add pixels 199 | */ 200 | for(int y = 0; y < height; y++){ 201 | for(int x = 0; x < width; x++){ 202 | //add the RGB components of the two source image 203 | pRED = sourceImg1.getRed(x, y) + C; 204 | pGREEN = sourceImg1.getGreen(x, y) + C; 205 | pBLUE = sourceImg1.getBlue(x, y) + C; 206 | 207 | //find result 208 | rRED = (pRED>255)?255:pRED; 209 | rGREEN = (pGREEN>255)?255:pGREEN; 210 | rBLUE = (pBLUE>255)?255:pBLUE; 211 | 212 | //save result 213 | resultImg.setPixel(x, y, 255, rRED, rGREEN, rBLUE); 214 | } 215 | } 216 | } 217 | }//class ends here 218 | -------------------------------------------------------------------------------- /DYimageFX-project/src/dyimagefx/math/Blend.java: -------------------------------------------------------------------------------- 1 | package dyimagefx.math; 2 | import dyimagefx.MyImage; 3 | 4 | /** 5 | * File: Blend.java 6 | * 7 | * Description: 8 | * To perform blending of image pixels. 9 | * 10 | * @author Yusuf Shakeel 11 | * @version 1.0 12 | * Date: 25-04-2014 fri 13 | * 14 | * www.github.com/yusufshakeel/Java-Image-Processing-Project 15 | * 16 | * The MIT License (MIT) 17 | * Copyright (c) 2014 Yusuf Shakeel 18 | * 19 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 20 | * this software and associated documentation files (the "Software"), to deal in 21 | * the Software without restriction, including without limitation the rights to 22 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 23 | * the Software, and to permit persons to whom the Software is furnished to do so, 24 | * subject to the following conditions 25 | * 26 | * The above copyright notice and this permission notice shall be included in all 27 | * copies or substantial portions of the Software. 28 | * 29 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 30 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 31 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 32 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 33 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 34 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 35 | */ 36 | 37 | public class Blend { 38 | 39 | /////////////////////////////// BINARY IMAGE //////////////////////////////// 40 | 41 | /** 42 | * This method will blend the pixels of the binary image. 43 | * It takes two equal size binary images and blend their pixels. 44 | * The result of blend is saved in resultImg which is also of the same size. 45 | * 46 | * @param sourceImg1 The first image. 47 | * @param sourceImg2 The second image. 48 | * @param resultImg This will hold the resultant image after blend of image1 and image2. 49 | * @param blendRatio The blend ratio. 50 | */ 51 | public static void binaryImage(MyImage sourceImg1, MyImage sourceImg2, MyImage resultImg, float blendRatio){ 52 | /** 53 | * Note grayscale and binary image pixel blend is almost same. 54 | * So, calling grayscaleImage() method 55 | */ 56 | grayscaleImage(sourceImg1, sourceImg2, resultImg, blendRatio); 57 | } 58 | 59 | /////////////////////////////// GRAYSCALE IMAGE //////////////////////////// 60 | 61 | /** 62 | * This method will blend the pixels of the grayscale image. 63 | * It takes two equal size grayscale images and blend their pixels. 64 | * The result of blend is saved in resultImg which is also of the same size. 65 | * 66 | * @param sourceImg1 The first image. 67 | * @param sourceImg2 The second image. 68 | * @param resultImg This will hold the resultant image after blend of image1 and image2. 69 | * @param blendRatio The blend ratio. 70 | */ 71 | public static void grayscaleImage(MyImage sourceImg1, MyImage sourceImg2, MyImage resultImg, float blendRatio){ 72 | 73 | //image dimension - common for all the three images 74 | int width = sourceImg1.getImageWidth(); 75 | int height = sourceImg1.getImageHeight(); 76 | 77 | //variable 78 | int result; 79 | 80 | /** 81 | * blend pixels 82 | * Grayscale image will have same value for RGB so take any one component. 83 | */ 84 | for(int y = 0; y < height; y++){ 85 | for(int x = 0; x < width; x++){ 86 | result = (int)((blendRatio*sourceImg1.getBlue(x, y)) + ((1-blendRatio)*sourceImg2.getBlue(x, y))); 87 | if(result > 255){ 88 | result = 255; 89 | }else if(result < 0){ 90 | result = 0; 91 | } 92 | resultImg.setPixel(x, y, 255, result, result, result); 93 | } 94 | } 95 | } 96 | 97 | /////////////////////////////// COLOR IMAGE //////////////////////////////// 98 | 99 | /** 100 | * This method will blend the pixels of the color image. 101 | * It takes two equal size color images and blend their pixels. 102 | * The result of blend is saved in resultImg which is also of the same size. 103 | * 104 | * @param sourceImg1 The first image. 105 | * @param sourceImg2 The second image. 106 | * @param resultImg This will hold the resultant image after blend of image1 and image2. 107 | * @param blendRatio The blend ratio. 108 | */ 109 | public static void colorImage(MyImage sourceImg1, MyImage sourceImg2, MyImage resultImg, float blendRatio){ 110 | 111 | //image dimension - common for all the three images 112 | int width = sourceImg1.getImageWidth(); 113 | int height = sourceImg1.getImageHeight(); 114 | 115 | //variable 116 | int rRED, rGREEN, rBLUE; 117 | 118 | /** 119 | * blend pixels 120 | */ 121 | for(int y = 0; y < height; y++){ 122 | for(int x = 0; x < width; x++){ 123 | //blend the RGB components of the two source image 124 | rRED = (int)((blendRatio*sourceImg1.getRed(x, y)) + ((1-blendRatio)*sourceImg2.getRed(x, y))); 125 | rGREEN = (int)((blendRatio*sourceImg1.getGreen(x, y)) + ((1-blendRatio)*sourceImg2.getGreen(x, y))); 126 | rBLUE = (int)((blendRatio*sourceImg1.getBlue(x, y)) + ((1-blendRatio)*sourceImg2.getBlue(x, y))); 127 | 128 | if(rRED>255){ 129 | rRED = 255; 130 | }else if(rRED<0){ 131 | rRED = 0; 132 | } 133 | 134 | if(rGREEN>255){ 135 | rGREEN = 255; 136 | }else if(rGREEN<0){ 137 | rGREEN = 0; 138 | } 139 | 140 | if(rBLUE>255){ 141 | rBLUE = 255; 142 | }else if(rBLUE<0){ 143 | rBLUE = 0; 144 | } 145 | 146 | //save result 147 | resultImg.setPixel(x, y, 255, rRED, rGREEN, rBLUE); 148 | } 149 | } 150 | } 151 | }//class ends here 152 | -------------------------------------------------------------------------------- /DYimageFX-project/src/dyimagefx/math/Divide.java: -------------------------------------------------------------------------------- 1 | package dyimagefx.math; 2 | import dyimagefx.MyImage; 3 | 4 | /** 5 | * File: Divide.java 6 | * 7 | * Description: 8 | * To perform division of image pixels. 9 | * 10 | * @author Yusuf Shakeel 11 | * @version 1.0 12 | * Date: 25-04-2014 fri 13 | * 14 | * www.github.com/yusufshakeel/Java-Image-Processing-Project 15 | * 16 | * The MIT License (MIT) 17 | * Copyright (c) 2014 Yusuf Shakeel 18 | * 19 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 20 | * this software and associated documentation files (the "Software"), to deal in 21 | * the Software without restriction, including without limitation the rights to 22 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 23 | * the Software, and to permit persons to whom the Software is furnished to do so, 24 | * subject to the following conditions 25 | * 26 | * The above copyright notice and this permission notice shall be included in all 27 | * copies or substantial portions of the Software. 28 | * 29 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 30 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 31 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 32 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 33 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 34 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 35 | */ 36 | public class Divide { 37 | 38 | /////////////////////////////// BINARY IMAGE //////////////////////////////// 39 | 40 | /** 41 | * This method will divide the pixels of the binary image. 42 | * It takes two equal size binary images and divides their pixels. 43 | * The result of division is saved in resultImg which is also of the same size. 44 | * 45 | * @param sourceImg1 The first image. 46 | * @param sourceImg2 The second image. 47 | * @param resultImg This will hold the resultant image after division of image1 and image2. 48 | */ 49 | public static void binaryImage(MyImage sourceImg1, MyImage sourceImg2, MyImage resultImg){ 50 | /** 51 | * Note grayscale and binary image pixel division is almost same. 52 | * So, calling grayscaleImage() method 53 | */ 54 | grayscaleImage(sourceImg1, sourceImg2, resultImg); 55 | } 56 | 57 | /** 58 | * This method will divide the pixels of the binary image. 59 | * It takes a binary images and divides its pixel with a constant value C. 60 | * The result of division is saved in resultImg which is of same size as sourceImage. 61 | * 62 | * @param sourceImg1 The first image. 63 | * @param C The constant to add. [0-255] 64 | * @param resultImg This will hold the resultant image after division of image1 and image2. 65 | */ 66 | public static void binaryImage(MyImage sourceImg1, int C, MyImage resultImg){ 67 | /** 68 | * Note grayscale and binary image pixel division is almost same. 69 | * So, calling grayscaleImage() method 70 | */ 71 | grayscaleImage(sourceImg1, C, resultImg); 72 | } 73 | 74 | /////////////////////////////// GRAYSCALE IMAGE //////////////////////////// 75 | 76 | /** 77 | * This method will division the pixels of the grayscale image. 78 | * It takes two equal size grayscale images and divides their pixels. 79 | * The result of divisions is saved in resultImg which is also of the same size. 80 | * 81 | * @param sourceImg1 The first image. 82 | * @param sourceImg2 The second image. 83 | * @param resultImg This will hold the resultant image after divisions of image1 and image2. 84 | */ 85 | public static void grayscaleImage(MyImage sourceImg1, MyImage sourceImg2, MyImage resultImg){ 86 | 87 | //image dimension - common for all the three images 88 | int width = sourceImg1.getImageWidth(); 89 | int height = sourceImg1.getImageHeight(); 90 | 91 | //variable 92 | int result; 93 | 94 | /** 95 | * divide pixels 96 | * Grayscale image will have same value for RGB so take any one component. 97 | */ 98 | for(int y = 0; y < height; y++){ 99 | for(int x = 0; x < width; x++){ 100 | if(sourceImg2.getBlue(x, y) > 0){ 101 | result = sourceImg1.getBlue(x, y) / sourceImg2.getBlue(x, y); 102 | }else{ 103 | result = 0; 104 | } 105 | resultImg.setPixel(x, y, 255, result, result, result); 106 | } 107 | } 108 | } 109 | 110 | /** 111 | * This method will divide the pixels of the grayscale image. 112 | * It takes a grayscale images and divides its pixel with a constant value C. 113 | * The result of division is saved in resultImg which is of the size of sourceImage. 114 | * 115 | * @param sourceImg1 The first image. 116 | * @param C constant number to add. [1-255] 117 | * @param resultImg This will hold the resultant image after divisions of image1 and image2. 118 | */ 119 | public static void grayscaleImage(MyImage sourceImg1, int C, MyImage resultImg){ 120 | 121 | //image dimension - common for the two images 122 | int width = sourceImg1.getImageWidth(); 123 | int height = sourceImg1.getImageHeight(); 124 | 125 | //variable 126 | int result; 127 | 128 | /** 129 | * divide pixels 130 | * Grayscale image will have same value for RGB so take any one component. 131 | */ 132 | for(int y = 0; y < height; y++){ 133 | for(int x = 0; x < width; x++){ 134 | result = sourceImg1.getBlue(x, y) / C; 135 | resultImg.setPixel(x, y, 255, result, result, result); 136 | } 137 | } 138 | } 139 | 140 | /////////////////////////////// COLOR IMAGE //////////////////////////////// 141 | 142 | /** 143 | * This method will divide the pixels of the color image. 144 | * It takes two equal size color images and divides their pixels. 145 | * The result of divisions is saved in resultImg which is also of the same size. 146 | * 147 | * @param sourceImg1 The first image. 148 | * @param sourceImg2 The second image. 149 | * @param resultImg This will hold the resultant image after divisions of image1 and image2. 150 | */ 151 | public static void colorImage(MyImage sourceImg1, MyImage sourceImg2, MyImage resultImg){ 152 | 153 | //image dimension - common for all the three images 154 | int width = sourceImg1.getImageWidth(); 155 | int height = sourceImg1.getImageHeight(); 156 | 157 | //variable 158 | int rRED, rGREEN, rBLUE; 159 | 160 | /** 161 | * divide pixels 162 | */ 163 | for(int y = 0; y < height; y++){ 164 | for(int x = 0; x < width; x++){ 165 | //divide 166 | if(sourceImg2.getRed(x, y) > 0){ 167 | rRED = sourceImg1.getRed(x, y) / sourceImg2.getRed(x, y); 168 | }else{ 169 | rRED = 0; 170 | } 171 | 172 | if(sourceImg2.getGreen(x, y) > 0){ 173 | rGREEN = sourceImg1.getGreen(x, y) / sourceImg2.getGreen(x, y); 174 | }else{ 175 | rGREEN = 0; 176 | } 177 | 178 | if(sourceImg2.getBlue(x, y) > 0){ 179 | rBLUE = sourceImg1.getBlue(x, y) / sourceImg2.getBlue(x, y); 180 | }else{ 181 | rBLUE = 0; 182 | } 183 | 184 | //save result 185 | resultImg.setPixel(x, y, 255, rRED, rGREEN, rBLUE); 186 | } 187 | } 188 | } 189 | 190 | /** 191 | * This method will divide the pixels of the color image. 192 | * It takes a color images and divides its pixel with a constant value C. 193 | * The result of division is saved in resultImg which is of the size of sourceImage. 194 | * 195 | * @param sourceImg1 The first image. 196 | * @param C The constant value to add. [1-255] 197 | * @param resultImg This will hold the resultant image after division of image1 and image2. 198 | */ 199 | public static void colorImage(MyImage sourceImg1, int C, MyImage resultImg){ 200 | 201 | //image dimension - common for all the three images 202 | int width = sourceImg1.getImageWidth(); 203 | int height = sourceImg1.getImageHeight(); 204 | 205 | //variable 206 | int rRED, rGREEN, rBLUE; 207 | 208 | /** 209 | * divide pixels 210 | */ 211 | for(int y = 0; y < height; y++){ 212 | for(int x = 0; x < width; x++){ 213 | //divide 214 | rRED = sourceImg1.getRed(x, y) / C; 215 | rGREEN = sourceImg1.getGreen(x, y) / C; 216 | rBLUE = sourceImg1.getBlue(x, y) / C; 217 | 218 | //save result 219 | resultImg.setPixel(x, y, 255, rRED, rGREEN, rBLUE); 220 | } 221 | } 222 | } 223 | }//class ends here 224 | -------------------------------------------------------------------------------- /DYimageFX-project/src/dyimagefx/morph/Closing.java: -------------------------------------------------------------------------------- 1 | package dyimagefx.morph; 2 | import dyimagefx.MyImage; 3 | 4 | /** 5 | * File: Closing.java 6 | * 7 | * Description: 8 | * Implements the image morphology operation: closing. 9 | * 10 | * CLosing is defined as dilation followed by erosion of image. 11 | * 12 | * WHITE is represented as (255,255,255,255) and BLACK as (255,0,0,0) in ARGB form respectively. 13 | * 14 | * @author Yusuf Shakeel 15 | * @version 1.0 16 | * date: 24-04-2014 Thu 17 | * 18 | * www.github.com/yusufshakeel/Java-Image-Processing-Project 19 | * 20 | * The MIT License (MIT) 21 | * Copyright (c) 2014 Yusuf Shakeel 22 | * 23 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 24 | * this software and associated documentation files (the "Software"), to deal in 25 | * the Software without restriction, including without limitation the rights to 26 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 27 | * the Software, and to permit persons to whom the Software is furnished to do so, 28 | * subject to the following conditions 29 | * 30 | * The above copyright notice and this permission notice shall be included in all 31 | * copies or substantial portions of the Software. 32 | * 33 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 34 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 35 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 36 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 37 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 38 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 39 | */ 40 | public class Closing { 41 | 42 | /** 43 | * This method will perform closing on binary image img. 44 | * 45 | * @param img The image on which opening is performed. 46 | */ 47 | public static void binaryImage(MyImage img){ 48 | Dilation.binaryImage(img, true); 49 | Erosion.binaryImage(img, true); 50 | } 51 | 52 | /** 53 | * This method will perform closing on grayscale image img. 54 | * 55 | * @param img The image on which opening is performed. 56 | * @param mask The square mask 57 | * @param maskSize The size of the square mask [No. of rows or columns of the square mask] 58 | */ 59 | public static void grayscaleImage(MyImage img, int mask[], int maskSize){ 60 | Dilation.grayscaleImage(img, mask, maskSize); 61 | Erosion.grayscaleImage(img, mask, maskSize); 62 | } 63 | }//class ends here 64 | -------------------------------------------------------------------------------- /DYimageFX-project/src/dyimagefx/morph/CornerPoints.java: -------------------------------------------------------------------------------- 1 | package dyimagefx.morph; 2 | import dyimagefx.MyImage; 3 | import dyimagefx.morph.HitMiss; 4 | import dyimagefx.math.LogicalOR; 5 | 6 | /** 7 | * File: CornerPoints.java 8 | * 9 | * Description: 10 | * This will find the corner points in the image. 11 | * It uses HitMiss morphological concept. 12 | * 13 | * @author Yusuf Shakeel 14 | * @version 1.0 15 | * date: 29-04-2014 tue 16 | * 17 | * www.github.com/yusufshakeel/Java-Image-Processing-Project 18 | * 19 | * The MIT License (MIT) 20 | * Copyright (c) 2014 Yusuf Shakeel 21 | * 22 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 23 | * this software and associated documentation files (the "Software"), to deal in 24 | * the Software without restriction, including without limitation the rights to 25 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 26 | * the Software, and to permit persons to whom the Software is furnished to do so, 27 | * subject to the following conditions 28 | * 29 | * The above copyright notice and this permission notice shall be included in all 30 | * copies or substantial portions of the Software. 31 | * 32 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 33 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 34 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 35 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 36 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 37 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 38 | */ 39 | public class CornerPoints { 40 | 41 | /** 42 | * This method will find the corner points of a binary image using hit-miss morphological technique. 43 | * 44 | * @param img The image on which corner points detection operation is performed 45 | * @return Binary Image having only corner points. 46 | */ 47 | public static void binaryImage(MyImage img){ 48 | 49 | /** 50 | * The 2D mask array has three types of values. 51 | * 0 for BLACK i.e., BACKGROUND 52 | * 1 for WHITE i.e., FOREGROUND 53 | * 2 for DON'T CARE 54 | * 55 | * How it works: 56 | * To find the corner points we perform the hit-miss operation 4 times on the image img 57 | * using 4 different mask separately. 58 | * Then we perform LogicalOR operation on the 4 images to get the final result. 59 | */ 60 | 61 | //1st hit-miss operation 62 | int mask1[] = new int[]{ 63 | 2,1,2, 64 | 0,1,1, 65 | 0,0,2 66 | }; 67 | MyImage img1 = new MyImage(img); 68 | HitMiss.binaryImage(img1, mask1, 3); 69 | 70 | //2nd hit-miss operation 71 | int mask2[] = new int[]{ 72 | 2,1,2, 73 | 1,1,0, 74 | 2,0,0 75 | }; 76 | MyImage img2 = new MyImage(img); 77 | HitMiss.binaryImage(img2, mask2, 3); 78 | 79 | //3rd hit-miss operation 80 | int mask3[] = new int[]{ 81 | 2,0,0, 82 | 1,1,0, 83 | 2,1,2 84 | }; 85 | MyImage img3 = new MyImage(img); 86 | HitMiss.binaryImage(img3, mask3, 3); 87 | 88 | //4th hit-miss operation 89 | int mask4[] = new int[]{ 90 | 0,0,2, 91 | 0,1,1, 92 | 2,1,2 93 | }; 94 | MyImage img4 = new MyImage(img); 95 | HitMiss.binaryImage(img4, mask4, 3); 96 | 97 | //LogicalOR the 4 images 98 | LogicalOR.binaryImage(img1, img2, img); 99 | LogicalOR.binaryImage(img, img3, img); 100 | LogicalOR.binaryImage(img, img4, img); 101 | } 102 | }//class ends here 103 | -------------------------------------------------------------------------------- /DYimageFX-project/src/dyimagefx/morph/HitMiss.java: -------------------------------------------------------------------------------- 1 | package dyimagefx.morph; 2 | import dyimagefx.MyImage; 3 | 4 | /** 5 | * File: HitMiss.java 6 | * 7 | * Description: 8 | * Implements the image morphology operation: hit-miss 9 | * 10 | * @author Yusuf Shakeel 11 | * @version 1.0 12 | * date: 29-04-2014 tue 13 | * 14 | * www.github.com/yusufshakeel/Java-Image-Processing-Project 15 | * 16 | * The MIT License (MIT) 17 | * Copyright (c) 2014 Yusuf Shakeel 18 | * 19 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 20 | * this software and associated documentation files (the "Software"), to deal in 21 | * the Software without restriction, including without limitation the rights to 22 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 23 | * the Software, and to permit persons to whom the Software is furnished to do so, 24 | * subject to the following conditions 25 | * 26 | * The above copyright notice and this permission notice shall be included in all 27 | * copies or substantial portions of the Software. 28 | * 29 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 30 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 31 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 32 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 33 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 34 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 35 | */ 36 | public class HitMiss { 37 | 38 | ///////////////////////// BINARY IMAGE ///////////////////////////////////// 39 | 40 | /** 41 | * This method will perform hit-miss operation on the binary image img. 42 | * A binary image has two types of pixels - Black and White. 43 | * WHITE pixel has the ARGB value (255,255,255,255) 44 | * BLACK pixel has the ARGB value (255,0,0,0) 45 | * 46 | * The 2D mask array has three types of values. 47 | * 0 for BLACK i.e., BACKGROUND 48 | * 1 for WHITE i.e., FOREGROUND 49 | * 2 for DON'T CARE 50 | * 51 | * @param img The image on which hit miss operation is performed 52 | * @param mask 2D array of square mask. 53 | * @param maskSize The size of the square mask - no. of rows. 54 | */ 55 | public static void binaryImage(MyImage img,int mask[], int maskSize){ 56 | /** 57 | * Dimension of the image img. 58 | */ 59 | int width = img.getImageWidth(); 60 | int height = img.getImageHeight(); 61 | 62 | /** 63 | * This will hold the dilation result which will be copied to image img. 64 | */ 65 | int output[] = new int[width * height]; 66 | 67 | //perform hit-miss 68 | for(int y = 0; y < height; y++){ 69 | for(int x = 0; x < width; x++){ 70 | boolean flag = false; //this will be set if mismatch is found 71 | for(int ty = y - (maskSize/2), mr = 0; ty <= y + (maskSize/2) && flag == false; ty++, mr++){ 72 | for(int tx = x - (maskSize/2), mc = 0; tx <= x + (maskSize/2) && flag == false; tx++, mc++){ 73 | //pixel under the mask 74 | if(ty >= 0 && ty < height && tx >= 0 && tx < width){ 75 | 76 | //for don't-care value in mask 77 | if(mask[mc+mr*maskSize] > 1){ 78 | continue; 79 | } 80 | 81 | //if image pixel not same as mask 82 | if(img.getRed(tx, ty) != (mask[mc+mr*maskSize]*255)){ 83 | flag = true; 84 | output[x+y*width] = 0; //BLACK 85 | break; 86 | } 87 | } 88 | } 89 | } 90 | if(flag == false){ 91 | //all pixels of image under the mask has matched 92 | output[x+y*width] = 255; //FOREGROUND COLOR WHITE 93 | } 94 | } 95 | } 96 | 97 | /** 98 | * Save the hit miss value in image img. 99 | */ 100 | for(int y = 0; y < height; y++){ 101 | for(int x = 0; x < width; x++){ 102 | int v = output[x+y*width]; 103 | img.setPixel(x, y, 255, v, v, v); 104 | } 105 | } 106 | } 107 | }//class ends here 108 | -------------------------------------------------------------------------------- /DYimageFX-project/src/dyimagefx/morph/Opening.java: -------------------------------------------------------------------------------- 1 | package dyimagefx.morph; 2 | import dyimagefx.MyImage; 3 | 4 | /** 5 | * File: Opening.java 6 | * 7 | * Description: 8 | * Implements the image morphology operation: opening. 9 | * 10 | * Opening is defined as an erosion followed by a dilation. 11 | * 12 | * WHITE is represented as (255,255,255,255) and BLACK as (255,0,0,0) in ARGB form respectively. 13 | * 14 | * @author Yusuf Shakeel 15 | * @version 1.0 16 | * date: 24-04-2014 Thu 17 | * 18 | * www.github.com/yusufshakeel/Java-Image-Processing-Project 19 | * 20 | * The MIT License (MIT) 21 | * Copyright (c) 2014 Yusuf Shakeel 22 | * 23 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 24 | * this software and associated documentation files (the "Software"), to deal in 25 | * the Software without restriction, including without limitation the rights to 26 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 27 | * the Software, and to permit persons to whom the Software is furnished to do so, 28 | * subject to the following conditions 29 | * 30 | * The above copyright notice and this permission notice shall be included in all 31 | * copies or substantial portions of the Software. 32 | * 33 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 34 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 35 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 36 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 37 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 38 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 39 | */ 40 | public class Opening { 41 | 42 | /** 43 | * This method will perform opening on image img. 44 | * 45 | * For erosion we generally consider foreground pixel. So, erodeBlackpixel = false 46 | * For dilation we generally consider the background pixel. So, dilateBlackPixel = true. 47 | * 48 | * @param img The image on which opening is performed. 49 | * @param erodeBlackPixel If set to TRUE will perform erosion on BLACK pixels else on WHITE pixels. 50 | * @param dilateBlackPixel If set to TRUE will perform dilation on BLACK pixels else on WHITE pixels. 51 | */ 52 | public static void binaryImage(MyImage img, boolean erodeBlackPixel, boolean dilateBlackPixel){ 53 | Erosion.binaryImage(img, erodeBlackPixel); 54 | Dilation.binaryImage(img, dilateBlackPixel); 55 | } 56 | }//class ends here 57 | -------------------------------------------------------------------------------- /DYimageFX-project/src/dyimagefx/morph/Skeletonization.java: -------------------------------------------------------------------------------- 1 | package dyimagefx.morph; 2 | import dyimagefx.MyImage; 3 | import dyimagefx.morph.Thinning; 4 | 5 | /** 6 | * File: Skeletonization.java 7 | * 8 | * Description: 9 | * This will create a thin the image. 10 | * It uses Thinning morphological concept. 11 | * 12 | * @author Yusuf Shakeel 13 | * @version 1.0 14 | * date: 29-04-2014 tue 15 | * 16 | * www.github.com/yusufshakeel/Java-Image-Processing-Project 17 | * 18 | * The MIT License (MIT) 19 | * Copyright (c) 2014 Yusuf Shakeel 20 | * 21 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 22 | * this software and associated documentation files (the "Software"), to deal in 23 | * the Software without restriction, including without limitation the rights to 24 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 25 | * the Software, and to permit persons to whom the Software is furnished to do so, 26 | * subject to the following conditions 27 | * 28 | * The above copyright notice and this permission notice shall be included in all 29 | * copies or substantial portions of the Software. 30 | * 31 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 32 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 33 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 34 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 35 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 36 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 37 | */ 38 | public class Skeletonization { 39 | 40 | /** 41 | * This method will perform skeletonization [thinning] operation on the binary image img. 42 | * 43 | * @param img The image to thin. 44 | */ 45 | public static void binaryImage(MyImage img){ 46 | 47 | //1st set of masks 48 | int mask1[] = new int[]{ 49 | 0,0,0, 50 | 2,1,2, 51 | 1,1,1 52 | }; 53 | int mask2[] = new int[]{ 54 | 0,2,1, 55 | 0,1,1, 56 | 0,2,1 57 | }; 58 | int mask3[] = new int[]{ 59 | 1,1,1, 60 | 2,1,2, 61 | 0,0,0 62 | }; 63 | int mask4[] = new int[]{ 64 | 1,2,0, 65 | 1,1,0, 66 | 1,2,0 67 | }; 68 | 69 | //2nd set of masks 70 | int mask5[] = new int[]{ 71 | 2,0,0, 72 | 1,1,0, 73 | 2,1,2 74 | }; 75 | int mask6[] = new int[]{ 76 | 0,0,2, 77 | 0,1,1, 78 | 2,1,2 79 | }; 80 | int mask7[] = new int[]{ 81 | 2,1,2, 82 | 0,1,1, 83 | 0,0,2 84 | }; 85 | int mask8[] = new int[]{ 86 | 2,1,2, 87 | 1,1,0, 88 | 2,0,0 89 | }; 90 | 91 | //thin image till no change occurs 92 | MyImage tmpImg; 93 | int count = 0; 94 | do{ 95 | tmpImg = new MyImage(img); 96 | 97 | //thin with mask1 98 | Thinning.binaryImage(img, mask1, 3); 99 | 100 | //thin with mask5 101 | Thinning.binaryImage(img, mask5, 3); 102 | 103 | //thin with rest of the masks 104 | Thinning.binaryImage(img, mask2, 3); 105 | Thinning.binaryImage(img, mask3, 3); 106 | Thinning.binaryImage(img, mask4, 3); 107 | Thinning.binaryImage(img, mask6, 3); 108 | Thinning.binaryImage(img, mask7, 3); 109 | Thinning.binaryImage(img, mask8, 3); 110 | 111 | count++; 112 | System.out.println("Skeletonization() Loop Executed: "+count+" times."); 113 | }while(img.isEqual(tmpImg) == false); //change occured, so continue with the loop 114 | } 115 | }//class ends here 116 | -------------------------------------------------------------------------------- /DYimageFX-project/src/dyimagefx/morph/Thinning.java: -------------------------------------------------------------------------------- 1 | package dyimagefx.morph; 2 | import dyimagefx.MyImage; 3 | import dyimagefx.math.Subtract; 4 | 5 | /** 6 | * File: Thinning.java 7 | * 8 | * Description: 9 | * Implements the image morphology operation: thinning 10 | * 11 | * @author Yusuf Shakeel 12 | * @version 1.0 13 | * date: 29-04-2014 tue 14 | * 15 | * www.github.com/yusufshakeel/Java-Image-Processing-Project 16 | * 17 | * The MIT License (MIT) 18 | * Copyright (c) 2014 Yusuf Shakeel 19 | * 20 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 21 | * this software and associated documentation files (the "Software"), to deal in 22 | * the Software without restriction, including without limitation the rights to 23 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 24 | * the Software, and to permit persons to whom the Software is furnished to do so, 25 | * subject to the following conditions 26 | * 27 | * The above copyright notice and this permission notice shall be included in all 28 | * copies or substantial portions of the Software. 29 | * 30 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 31 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 32 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 33 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 34 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 35 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 36 | */ 37 | public class Thinning { 38 | 39 | /** 40 | * This method will perform thinning operation on the binary image. 41 | * 42 | * @param img The binary image on which thinning is performed. 43 | * @param mask The mask used for thinning. [Mask is a 2D matrix stored in 1D array] 44 | * @param maskSize The size of the mask. [No. of rows in the 2D mask matrix] 45 | */ 46 | public static void binaryImage(MyImage img, int mask[], int maskSize){ 47 | /** 48 | * How it works: 49 | * If we consider an image I and a mask M, then thinning T can be expressed as: 50 | * T(I,M) = I - HitMiss(I,M) 51 | */ 52 | MyImage tmp = new MyImage(img); 53 | HitMiss.binaryImage(tmp, mask, maskSize); 54 | Subtract.binaryImage(img, tmp, img); 55 | } 56 | }//class ends here 57 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Yusuf Shakeel 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Java-Image-Processing-Project 2 | ============================= 3 | 4 | DYimageFX - Open Source - Image Processing project 5 | 6 | By: Yusuf Shakeel 7 | 8 | Date: 26 January 2014 Sunday 9 | 10 | 11 | [facebook.com/yusufshakeel](https://www.facebook.com/yusufshakeel) 12 | 13 | [youtube.com/yusufshakeel](https://www.youtube.com/yusufshakeel) 14 | 15 | [github.com/yusufshakeel](https://www.github.com/yusufshakeel) 16 | 17 | [plus.google.com/+YusufShakeel](https://plus.google.com/+YusufShakeel/posts) 18 | 19 | 20 | Note 21 | ---- 22 | This project is in development stage so files will get modified quite often. 23 | 24 | I have used NetBeans IDE 7.3.1 for this project. It is a free software and you can download it from there website [netbeans.org] (https://netbeans.org) 25 | 26 | 27 | ### Project wiki [https://github.com/yusufshakeel/Java-Image-Processing-Project/wiki] (https://github.com/yusufshakeel/Java-Image-Processing-Project/wiki) 28 | 29 | ### Download [DYimageFX-jar](https://github.com/yusufshakeel/Java-Image-Processing-Project/tree/master/DYimageFX-jar) file to use it in your project. 30 | 31 | ### Download [DYimageFX-javadoc](https://github.com/yusufshakeel/Java-Image-Processing-Project/blob/master/DYimageFX-javadoc) for more details. 32 | 33 | 34 | ### You can also download the entire [project code](https://github.com/yusufshakeel/Java-Image-Processing-Project/archive/master.zip). 35 | 36 | 37 | # License 38 | 39 | The MIT License (MIT) 40 | 41 | Copyright (c) 2014 Yusuf Shakeel 42 | 43 | Permission is hereby granted, free of charge, to any person obtaining a copy of 44 | this software and associated documentation files (the "Software"), to deal in 45 | the Software without restriction, including without limitation the rights to 46 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 47 | the Software, and to permit persons to whom the Software is furnished to do so, 48 | subject to the following conditions: 49 | 50 | The above copyright notice and this permission notice shall be included in all 51 | copies or substantial portions of the Software. 52 | 53 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 54 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 55 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 56 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 57 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 58 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 59 | -------------------------------------------------------------------------------- /example/BlueImage.java: -------------------------------------------------------------------------------- 1 | /** 2 | * File: BlueImage.java 3 | * 4 | * Description: 5 | * Convert color image to blue image. 6 | * 7 | * @author Yusuf Shakeel 8 | * Date: 27-01-2014 mon 9 | * 10 | * www.github.com/yusufshakeel/Java-Image-Processing-Project 11 | */ 12 | 13 | import java.io.File; 14 | import java.io.IOException; 15 | import java.awt.image.BufferedImage; 16 | import javax.imageio.ImageIO; 17 | 18 | public class BlueImage{ 19 | public static void main(String args[])throws IOException{ 20 | BufferedImage img = null; 21 | File f = null; 22 | 23 | //read image 24 | try{ 25 | f = new File("D:\\Image\\sonam.jpg"); 26 | img = ImageIO.read(f); 27 | }catch(IOException e){ 28 | System.out.println(e); 29 | } 30 | 31 | //get width and height 32 | int width = img.getWidth(); 33 | int height = img.getHeight(); 34 | 35 | //convert to blue image 36 | for(int y = 0; y < height; y++){ 37 | for(int x = 0; x < width; x++){ 38 | int p = img.getRGB(x,y); 39 | 40 | int a = (p>>24)&0xff; 41 | int b = p&0xff; 42 | 43 | //set new RGB 44 | p = (a<<24) | (0<<16) | (0<<8) | b; 45 | 46 | img.setRGB(x, y, p); 47 | } 48 | } 49 | 50 | //write image 51 | try{ 52 | f = new File("D:\\Image\\output.jpg"); 53 | ImageIO.write(img, "jpg", f); 54 | }catch(IOException e){ 55 | System.out.println(e); 56 | } 57 | }//main() ends here 58 | }//class ends here -------------------------------------------------------------------------------- /example/Grayscale.java: -------------------------------------------------------------------------------- 1 | /** 2 | * File: Grayscale.java 3 | * 4 | * Description: 5 | * Convert color image into grayscale image. 6 | * 7 | * @author Yusuf Shakeel 8 | * Date: 26-01-2014 sun 9 | * 10 | * www.github.com/yusufshakeel/Java-Image-Processing-Project 11 | */ 12 | 13 | import java.io.File; 14 | import java.io.IOException; 15 | import java.awt.image.BufferedImage; 16 | import javax.imageio.ImageIO; 17 | 18 | public class Grayscale{ 19 | public static void main(String args[])throws IOException{ 20 | BufferedImage img = null; 21 | File f = null; 22 | 23 | //read image 24 | try{ 25 | f = new File("D:\\Image\\Taj.jpg"); 26 | img = ImageIO.read(f); 27 | }catch(IOException e){ 28 | System.out.println(e); 29 | } 30 | 31 | //get image width and height 32 | int width = img.getWidth(); 33 | int height = img.getHeight(); 34 | 35 | //convert to grayscale 36 | for(int y = 0; y < height; y++){ 37 | for(int x = 0; x < width; x++){ 38 | int p = img.getRGB(x,y); 39 | 40 | int a = (p>>24)&0xff; 41 | int r = (p>>16)&0xff; 42 | int g = (p>>8)&0xff; 43 | int b = p&0xff; 44 | 45 | //calculate average 46 | int avg = (r+g+b)/3; 47 | 48 | //replace RGB value with avg 49 | p = (a<<24) | (avg<<16) | (avg<<8) | avg; 50 | 51 | img.setRGB(x, y, p); 52 | } 53 | } 54 | 55 | //write image 56 | try{ 57 | f = new File("D:\\Image\\Output.jpg"); 58 | ImageIO.write(img, "jpg", f); 59 | }catch(IOException e){ 60 | System.out.println(e); 61 | } 62 | }//main() ends here 63 | }//class ends here -------------------------------------------------------------------------------- /example/GreenImage.java: -------------------------------------------------------------------------------- 1 | /** 2 | * File: GreenImage.java 3 | * 4 | * Description: 5 | * Convert color image to green image. 6 | * 7 | * @author Yusuf Shakeel 8 | * Date: 27-01-2014 mon 9 | * 10 | * www.github.com/yusufshakeel/Java-Image-Processing-Project 11 | */ 12 | 13 | import java.io.File; 14 | import java.io.IOException; 15 | import java.awt.image.BufferedImage; 16 | import javax.imageio.ImageIO; 17 | 18 | public class GreenImage{ 19 | public static void main(String args[])throws IOException{ 20 | BufferedImage img = null; 21 | File f = null; 22 | 23 | //read image 24 | try{ 25 | f = new File("D:\\Image\\sonam.jpg"); 26 | img = ImageIO.read(f); 27 | }catch(IOException e){ 28 | System.out.println(e); 29 | } 30 | 31 | //get width and height 32 | int width = img.getWidth(); 33 | int height = img.getHeight(); 34 | 35 | //convert to green image 36 | for(int y = 0; y < height; y++){ 37 | for(int x = 0; x < width; x++){ 38 | int p = img.getRGB(x,y); 39 | 40 | int a = (p>>24)&0xff; 41 | int g = (p>>8)&0xff; 42 | 43 | //set new RGB 44 | p = (a<<24) | (0<<16) | (g<<8) | 0; 45 | 46 | img.setRGB(x, y, p); 47 | } 48 | } 49 | 50 | //write image 51 | try{ 52 | f = new File("D:\\Image\\output.jpg"); 53 | ImageIO.write(img, "jpg", f); 54 | }catch(IOException e){ 55 | System.out.println(e); 56 | } 57 | }//main() ends here 58 | }//class ends here -------------------------------------------------------------------------------- /example/MirrorImage.java: -------------------------------------------------------------------------------- 1 | /** 2 | * File: MirrorImage.java 3 | * 4 | * Description: 5 | * Create a mirror image. 6 | * 7 | * @author Yusuf Shakeel 8 | * Date: 04-04-2014 fri 9 | */ 10 | 11 | import java.io.File; 12 | import java.io.IOException; 13 | import java.awt.image.BufferedImage; 14 | import javax.imageio.ImageIO; 15 | 16 | public class MirrorImage{ 17 | public static void main(String args[])throws IOException{ 18 | //BufferedImage for source image 19 | BufferedImage simg = null; 20 | 21 | //File object 22 | File f = null; 23 | 24 | //read source image file 25 | try{ 26 | f = new File("D:\\Image\\audrey.jpg"); 27 | simg = ImageIO.read(f); 28 | }catch(IOException e){ 29 | System.out.println("Error: " + e); 30 | } 31 | 32 | //get source image dimension 33 | int width = simg.getWidth(); 34 | int height = simg.getHeight(); 35 | 36 | //BufferedImage for mirror image 37 | BufferedImage mimg = new BufferedImage(width*2, height, BufferedImage.TYPE_INT_ARGB); 38 | 39 | //create mirror image pixel by pixel 40 | for(int y = 0; y < height; y++){ 41 | for(int lx = 0, rx = width*2 - 1; lx < width; lx++, rx--){ 42 | //lx starts from the left side of the image 43 | //rx starts from the right side of the image 44 | 45 | //get source pixel value 46 | int p = simg.getRGB(lx, y); 47 | 48 | //set mirror image pixel value - both left and right 49 | mimg.setRGB(lx, y, p); 50 | mimg.setRGB(rx, y, p); 51 | } 52 | } 53 | 54 | //save mirror image 55 | try{ 56 | f = new File("D:\\Image\\Output.png"); 57 | ImageIO.write(mimg, "png", f); 58 | }catch(IOException e){ 59 | System.out.println("Error: " + e); 60 | } 61 | }//main() ends here 62 | }//class ends here -------------------------------------------------------------------------------- /example/MyImage.java: -------------------------------------------------------------------------------- 1 | /** 2 | * File: MyImage.java 3 | * 4 | * Description: 5 | * Read and write image. 6 | * 7 | * @author Yusuf Shakeel 8 | * Date: 26-01-2014 sun 9 | * 10 | * www.github.com/yusufshakeel/Java-Image-Processing-Project 11 | */ 12 | 13 | import java.io.File; 14 | import java.io.IOException; 15 | import java.awt.image.BufferedImage; 16 | import javax.imageio.ImageIO; 17 | 18 | public class MyImage{ 19 | public static void main(String args[])throws IOException{ 20 | int width = 963; //width of the image 21 | int height = 640; //height of the image 22 | BufferedImage image = null; 23 | File f = null; 24 | 25 | //read image file 26 | try{ 27 | f = new File("D:\\Image\\Taj.jpg"); //image file path 28 | image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); 29 | image = ImageIO.read(f); 30 | System.out.println("Reading complete."); 31 | }catch(IOException e){ 32 | System.out.println("Error: "+e); 33 | } 34 | 35 | //write image 36 | try{ 37 | f = new File("D:\\Image\\Output.jpg"); //output file path 38 | ImageIO.write(image, "jpg", f); 39 | System.out.println("Writing complete."); 40 | }catch(IOException e){ 41 | System.out.println("Error: "+e); 42 | } 43 | }//main() ends here 44 | }//class ends here -------------------------------------------------------------------------------- /example/Negative.java: -------------------------------------------------------------------------------- 1 | /** 2 | * File: Negative.java 3 | * 4 | * Description: 5 | * Convert color image to negative. 6 | * 7 | * @author Yusuf Shakeel 8 | * Date: 27-01-2014 mon 9 | * 10 | * www.github.com/yusufshakeel/Java-Image-Processing-Project 11 | */ 12 | 13 | import java.io.File; 14 | import java.io.IOException; 15 | import java.awt.image.BufferedImage; 16 | import javax.imageio.ImageIO; 17 | 18 | public class Negative{ 19 | public static void main(String args[])throws IOException{ 20 | BufferedImage img = null; 21 | File f = null; 22 | 23 | //read image 24 | try{ 25 | f = new File("D:\\Image\\Taj.jpg"); 26 | img = ImageIO.read(f); 27 | }catch(IOException e){ 28 | System.out.println(e); 29 | } 30 | 31 | //get image width and height 32 | int width = img.getWidth(); 33 | int height = img.getHeight(); 34 | 35 | //convert to negative 36 | for(int y = 0; y < height; y++){ 37 | for(int x = 0; x < width; x++){ 38 | int p = img.getRGB(x,y); 39 | 40 | int a = (p>>24)&0xff; 41 | int r = (p>>16)&0xff; 42 | int g = (p>>8)&0xff; 43 | int b = p&0xff; 44 | 45 | //subtract RGB from 255 46 | r = 255 - r; 47 | g = 255 - g; 48 | b = 255 - b; 49 | 50 | //set new RGB value 51 | p = (a<<24) | (r<<16) | (g<<8) | b; 52 | 53 | img.setRGB(x, y, p); 54 | } 55 | } 56 | 57 | //write image 58 | try{ 59 | f = new File("D:\\Image\\Output.jpg"); 60 | ImageIO.write(img, "jpg", f); 61 | }catch(IOException e){ 62 | System.out.println(e); 63 | } 64 | }//main() ends here 65 | }//class ends here -------------------------------------------------------------------------------- /example/RandomImage.java: -------------------------------------------------------------------------------- 1 | /** 2 | * File: RandomImage.java 3 | * 4 | * Description: 5 | * Create a random color image. 6 | * 7 | * @author Yusuf Shakeel 8 | * Date: 01-04-2014 tue 9 | */ 10 | 11 | import java.io.File; 12 | import java.io.IOException; 13 | import java.awt.image.BufferedImage; 14 | import javax.imageio.ImageIO; 15 | 16 | public class RandomImage{ 17 | public static void main(String args[])throws IOException{ 18 | //image dimension 19 | int width = 640; 20 | int height = 320; 21 | 22 | //create buffered image object img 23 | BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); 24 | 25 | //file object 26 | File f = null; 27 | 28 | //create random image pixel by pixel 29 | for(int y = 0; y < height; y++){ 30 | for(int x = 0; x < width; x++){ 31 | int a = (int)(Math.random()*256); //alpha 32 | int r = (int)(Math.random()*256); //red 33 | int g = (int)(Math.random()*256); //green 34 | int b = (int)(Math.random()*256); //blue 35 | 36 | int p = (a<<24) | (r<<16) | (g<<8) | b; //pixel 37 | 38 | img.setRGB(x, y, p); 39 | } 40 | } 41 | 42 | //write image 43 | try{ 44 | f = new File("D:\\Image\\Output.png"); 45 | ImageIO.write(img, "png", f); 46 | }catch(IOException e){ 47 | System.out.println("Error: " + e); 48 | } 49 | }//main() ends here 50 | }//class ends here -------------------------------------------------------------------------------- /example/ReadWriteImage.java: -------------------------------------------------------------------------------- 1 | /** 2 | * File: ReadWriteImage.java 3 | * 4 | * Description: 5 | * Read and write image. 6 | * @author Yusuf Shakeel 7 | * Date: 26-01-2014 sun 8 | * 9 | * www.github.com/yusufshakeel/Java-Image-Processing-Project 10 | */ 11 | 12 | import java.io.File; 13 | import java.io.IOException; 14 | import java.awt.image.BufferedImage; 15 | import javax.imageio.ImageIO; 16 | 17 | public class MyImage{ 18 | public static void main(String args[])throws IOException{ 19 | BufferedImage image = null; 20 | File f = null; 21 | 22 | //read image file 23 | try{ 24 | f = new File("D:\\Image\\Taj.jpg"); 25 | image = ImageIO.read(f); 26 | }catch(IOException e){ 27 | System.out.println("Error: "+e); 28 | } 29 | 30 | //write image 31 | try{ 32 | f = new File("D:\\Image\\Output.jpg"); 33 | ImageIO.write(image, "jpg", f); 34 | }catch(IOException e){ 35 | System.out.println("Error: "+e); 36 | } 37 | }//main() ends here 38 | }//class ends here -------------------------------------------------------------------------------- /example/RedImage.java: -------------------------------------------------------------------------------- 1 | /** 2 | * File: RedImage.java 3 | * 4 | * Description: 5 | * Convert color image to red image. 6 | * 7 | * @author Yusuf Shakeel 8 | * Date: 27-01-2014 mon 9 | * 10 | * www.github.com/yusufshakeel/Java-Image-Processing-Project 11 | */ 12 | 13 | import java.io.File; 14 | import java.io.IOException; 15 | import java.awt.image.BufferedImage; 16 | import javax.imageio.ImageIO; 17 | 18 | public class RedImage{ 19 | public static void main(String args[])throws IOException{ 20 | BufferedImage img = null; 21 | File f = null; 22 | 23 | //read image 24 | try{ 25 | f = new File("D:\\Image\\sonam.jpg"); 26 | img = ImageIO.read(f); 27 | }catch(IOException e){ 28 | System.out.println(e); 29 | } 30 | 31 | //get width and height 32 | int width = img.getWidth(); 33 | int height = img.getHeight(); 34 | 35 | //convert to red image 36 | for(int y = 0; y < height; y++){ 37 | for(int x = 0; x < width; x++){ 38 | int p = img.getRGB(x,y); 39 | 40 | int a = (p>>24)&0xff; 41 | int r = (p>>16)&0xff; 42 | 43 | //set new RGB 44 | p = (a<<24) | (r<<16) | (0<<8) | 0; 45 | 46 | img.setRGB(x, y, p); 47 | } 48 | } 49 | 50 | //write image 51 | try{ 52 | f = new File("D:\\Image\\output.jpg"); 53 | ImageIO.write(img, "jpg", f); 54 | }catch(IOException e){ 55 | System.out.println(e); 56 | } 57 | }//main() ends here 58 | }//class ends here -------------------------------------------------------------------------------- /example/Sepia.java: -------------------------------------------------------------------------------- 1 | /** 2 | * File: Sepia.java 3 | * 4 | * Description: 5 | * Convert color image to sepia image. 6 | * 7 | * @author Yusuf Shakeel 8 | * Date: 27-01-2014 mon 9 | * 10 | * www.github.com/yusufshakeel/Java-Image-Processing-Project 11 | */ 12 | 13 | import java.io.File; 14 | import java.io.IOException; 15 | import java.awt.image.BufferedImage; 16 | import javax.imageio.ImageIO; 17 | 18 | public class Sepia{ 19 | public static void main(String args[])throws IOException{ 20 | BufferedImage img = null; 21 | File f = null; 22 | 23 | //read image 24 | try{ 25 | f = new File("D:\\Image\\zeenat.jpg"); 26 | img = ImageIO.read(f); 27 | }catch(IOException e){ 28 | System.out.println(e); 29 | } 30 | 31 | //get width and height of the image 32 | int width = img.getWidth(); 33 | int height = img.getHeight(); 34 | 35 | //convert to sepia 36 | for(int y = 0; y < height; y++){ 37 | for(int x = 0; x < width; x++){ 38 | int p = img.getRGB(x,y); 39 | 40 | int a = (p>>24)&0xff; 41 | int r = (p>>16)&0xff; 42 | int g = (p>>8)&0xff; 43 | int b = p&0xff; 44 | 45 | //calculate tr, tg, tb 46 | int tr = (int)(0.393*r + 0.769*g + 0.189*b); 47 | int tg = (int)(0.349*r + 0.686*g + 0.168*b); 48 | int tb = (int)(0.272*r + 0.534*g + 0.131*b); 49 | 50 | //check condition 51 | if(tr > 255){ 52 | r = 255; 53 | }else{ 54 | r = tr; 55 | } 56 | 57 | if(tg > 255){ 58 | g = 255; 59 | }else{ 60 | g = tg; 61 | } 62 | 63 | if(tb > 255){ 64 | b = 255; 65 | }else{ 66 | b = tb; 67 | } 68 | 69 | //set new RGB value 70 | p = (a<<24) | (r<<16) | (g<<8) | b; 71 | 72 | img.setRGB(x, y, p); 73 | } 74 | } 75 | 76 | //write image 77 | try{ 78 | f = new File("D:\\Image\\Output.jpg"); 79 | ImageIO.write(img, "jpg", f); 80 | }catch(IOException e){ 81 | System.out.println(e); 82 | } 83 | }//main() ends here 84 | }//class ends here -------------------------------------------------------------------------------- /src/imageFX/CornerPoints.java: -------------------------------------------------------------------------------- 1 | package imageFX; 2 | import imageFX.morph.HitMiss; 3 | import imageFX.math.LogicalOR; 4 | 5 | /** 6 | * File: CornerPoints.java 7 | * 8 | * Description: 9 | * This will find the corner points in the image. 10 | * It uses HitMiss morphological concept. 11 | * 12 | * @author Yusuf Shakeel 13 | * @version 1.0 14 | * date: 29-04-2014 tue 15 | * 16 | * www.github.com/yusufshakeel/Java-Image-Processing-Project 17 | * 18 | * The MIT License (MIT) 19 | * Copyright (c) 2014 Yusuf Shakeel 20 | * 21 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 22 | * this software and associated documentation files (the "Software"), to deal in 23 | * the Software without restriction, including without limitation the rights to 24 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 25 | * the Software, and to permit persons to whom the Software is furnished to do so, 26 | * subject to the following conditions 27 | * 28 | * The above copyright notice and this permission notice shall be included in all 29 | * copies or substantial portions of the Software. 30 | * 31 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 32 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 33 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 34 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 35 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 36 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 37 | */ 38 | public class CornerPoints { 39 | 40 | /** 41 | * This method will find the corner points of a binary image using hit-miss morphological technique. 42 | * 43 | * @param img The image on which corner points detection operation is performed 44 | * @return Binary Image having only corner points. 45 | */ 46 | public static void binaryImage(MyImage img){ 47 | 48 | /** 49 | * The 2D mask array has three types of values. 50 | * 0 for BLACK i.e., BACKGROUND 51 | * 1 for WHITE i.e., FOREGROUND 52 | * 2 for DON'T CARE 53 | * 54 | * How it works: 55 | * To find the corner points we perform the hit-miss operation 4 times on the image img 56 | * using 4 different mask separately. 57 | * Then we perform LogicalOR operation on the 4 images to get the final result. 58 | */ 59 | 60 | //1st hit-miss operation 61 | int mask1[] = new int[]{ 62 | 2,1,2, 63 | 0,1,1, 64 | 0,0,2 65 | }; 66 | MyImage img1 = new MyImage(img); 67 | HitMiss.binaryImage(img1, mask1, 3); 68 | 69 | //2nd hit-miss operation 70 | int mask2[] = new int[]{ 71 | 2,1,2, 72 | 1,1,0, 73 | 2,0,0 74 | }; 75 | MyImage img2 = new MyImage(img); 76 | HitMiss.binaryImage(img2, mask2, 3); 77 | 78 | //3rd hit-miss operation 79 | int mask3[] = new int[]{ 80 | 2,0,0, 81 | 1,1,0, 82 | 2,1,2 83 | }; 84 | MyImage img3 = new MyImage(img); 85 | HitMiss.binaryImage(img3, mask3, 3); 86 | 87 | //4th hit-miss operation 88 | int mask4[] = new int[]{ 89 | 0,0,2, 90 | 0,1,1, 91 | 2,1,2 92 | }; 93 | MyImage img4 = new MyImage(img); 94 | HitMiss.binaryImage(img4, mask4, 3); 95 | 96 | //LogicalOR the 4 images 97 | LogicalOR.binaryImage(img1, img2, img); 98 | LogicalOR.binaryImage(img, img3, img); 99 | LogicalOR.binaryImage(img, img4, img); 100 | } 101 | }//class ends here 102 | -------------------------------------------------------------------------------- /src/imageFX/DYMosaic.java: -------------------------------------------------------------------------------- 1 | package imageFX; 2 | /** 3 | * File: DYMosaic.java 4 | * 5 | * Description: 6 | * This file contains methods to create random mosaic. 7 | * 8 | * @author Yusuf Shakeel 9 | * @version 1.0 10 | * Date: 21-02-2014 fri 11 | * 12 | * www.github.com/yusufshakeel/Java-Image-Processing-Project 13 | * 14 | * The MIT License (MIT) 15 | * Copyright (c) 2014 Yusuf Shakeel 16 | * 17 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 18 | * this software and associated documentation files (the "Software"), to deal in 19 | * the Software without restriction, including without limitation the rights to 20 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 21 | * the Software, and to permit persons to whom the Software is furnished to do so, 22 | * subject to the following conditions 23 | * 24 | * The above copyright notice and this permission notice shall be included in all 25 | * copies or substantial portions of the Software. 26 | * 27 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 28 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 29 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 30 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 31 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 32 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 33 | */ 34 | public class DYMosaic { 35 | 36 | 37 | //////////////////////////////// MOSAIC Method ///////////////////////////// 38 | 39 | /** 40 | * This will create the mosaic. 41 | * 42 | * @param img The image object. 43 | * @param DYColor The hex color code. 44 | * @param mSize the mosaic piece size. 45 | */ 46 | private static void _createMosaic(MyImage img, int DYColor, int mSize){ 47 | int r = (DYColor>>16)&0xFF; 48 | int g = (DYColor>>8)&0xFF; 49 | int b = DYColor&0xFF; 50 | 51 | int buff = 20; 52 | int lim = Math.max(Math.max(r, g), b); 53 | lim = (((255-lim)/2)>buff)?buff:((255-lim)/2); 54 | 55 | //image dimension 56 | int width = img.getImageWidth(); 57 | int height = img.getImageHeight(); 58 | 59 | for(int y = 0; y < height; y += mSize){ 60 | for(int x = 0; x < width; x += mSize){ 61 | int c; 62 | if(lim>0){ 63 | c = (int)(Math.random()*lim); 64 | c = ((int)(Math.random()*2))==0?c:-1*c; 65 | }else{ 66 | lim = buff; 67 | c = -1*(int)(Math.random()*lim); 68 | } 69 | 70 | int[] rgb = new int[3]; 71 | rgb[0] = (c+r)>0?(c+r):r; 72 | rgb[1] = (c+g)>0?(c+g):g; 73 | rgb[2] = (c+b)>0?(c+b):b; 74 | 75 | for(int yi = 0; yi < mSize && y+yi < height; yi++){ 76 | for(int xi = 0; xi < mSize && x+xi < width; xi++){ 77 | img.setPixel(x+xi, y+yi, 255, rgb[0], rgb[1], rgb[2]); 78 | } 79 | } 80 | } 81 | } 82 | } 83 | 84 | /** 85 | * This method will generate a random mosaic pattern. 86 | * 87 | * @param img The image object. 88 | * @param DYColor The Hex color code. 89 | * @param pieceSize The piece size. [Mosaic pieces will be in square shape] 90 | */ 91 | public static void _random(MyImage img, int DYColor, int pieceSize){ 92 | int r = (int)(Math.random()*256); 93 | int g = (int)(Math.random()*256); 94 | int b = (int)(Math.random()*256); 95 | int color = (255<<24) | (r<<16) | (g<<8) | b; 96 | _createMosaic(img, color, pieceSize); 97 | } 98 | 99 | /** 100 | * This method will generate a color mosaic pattern. 101 | * 102 | * @param img The image object. 103 | * @param DYColor The Hex color code. 104 | * @param pieceSize The piece size. [Mosaic pieces will be in square shape] 105 | */ 106 | public static void myColorMosaic(MyImage img, int DYColor, int pieceSize){ 107 | _createMosaic(img, DYColor, pieceSize); 108 | } 109 | 110 | /** 111 | * This method will generate a color mosaic pattern based on the RGB value entered. 112 | * 113 | * @param img The image object 114 | * @param r The red value [0-255]. 115 | * @param g The green value [0-255]. 116 | * @param b The blue value [0-255]. 117 | * @param pieceSize The piece size. [Mosaic pieces will be in square shape] 118 | */ 119 | public static void myRGBMosaic(MyImage img, int r, int g, int b, int pieceSize){ 120 | int DYColor = (255<<24) | (r<<16) | (g<<8) | b; 121 | _createMosaic(img, DYColor, pieceSize); 122 | } 123 | }//class Mosaic ends here -------------------------------------------------------------------------------- /src/imageFX/Detect.java: -------------------------------------------------------------------------------- 1 | package imageFX; 2 | import static imageFX.ImageFX.getAlphaValueFromPixelValue; 3 | import static imageFX.ImageFX.getBlueValueFromPixelValue; 4 | import static imageFX.ImageFX.getGreenValueFromPixelValue; 5 | import static imageFX.ImageFX.getPixelValueFromARGBValue; 6 | import static imageFX.ImageFX.getRedValueFromPixelValue; 7 | 8 | /** 9 | * File: Detect.java 10 | * 11 | * Description: 12 | * This file contains edge/line detection methods. 13 | * 14 | * @author Yusuf Shakeel 15 | * @version 1.0 16 | * Date: 25-04-2014 fri 17 | * 18 | * www.github.com/yusufshakeel/Java-Image-Processing-Project 19 | * 20 | * The MIT License (MIT) 21 | * Copyright (c) 2014 Yusuf Shakeel 22 | * 23 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 24 | * this software and associated documentation files (the "Software"), to deal in 25 | * the Software without restriction, including without limitation the rights to 26 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 27 | * the Software, and to permit persons to whom the Software is furnished to do so, 28 | * subject to the following conditions 29 | * 30 | * The above copyright notice and this permission notice shall be included in all 31 | * copies or substantial portions of the Software. 32 | * 33 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 34 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 35 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 36 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 37 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 38 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 39 | */ 40 | public class Detect { 41 | 42 | //////////////////////////////// EDGE DETECT METHOD //////////////////////// 43 | 44 | /** 45 | * This method will detect edges in the image 46 | * mask[ -1, -1, -1, 47 | * -1, 8, -1, 48 | * -1, -1, -1] 49 | * 50 | * @param img The image to blur. 51 | */ 52 | public static void edgeDetect(MyImage img){ 53 | 54 | /** 55 | * Mask is a 2D square of odd size like 3x3 56 | * For simplicity storing it into 1D array. 57 | */ 58 | int mask[] = new int[]{ -1, -1, -1, 59 | -1, 8, -1, 60 | -1, -1, -1}; 61 | 62 | int maskSize = 3; //The width of the mask. 63 | 64 | /** 65 | * Buffered array of pixels holds the intermediate value of pixels that 66 | * is multiplied with the mask to get the final value for the center 67 | * pixel under the mask. 68 | */ 69 | int buff[]; 70 | 71 | /** 72 | * This array will store the output of the median filter operation which will 73 | * be later written back to the original image pixels. 74 | */ 75 | int outputPixels[] = new int[img.getImageTotalPixels()]; 76 | 77 | //image dimension 78 | int width = img.getImageWidth(); 79 | int height = img.getImageHeight(); 80 | 81 | /** Sharpen operation */ 82 | for(int y = 0; y < height; y++){ 83 | for(int x = 0; x < width; x++){ 84 | /** Fill buff array */ 85 | int i = 0; 86 | buff = new int[9]; 87 | for(int r = y - (maskSize / 2); r <= y + (maskSize / 2); r++){ 88 | for(int c = x - (maskSize / 2); c <= x + (maskSize / 2); c++){ 89 | if(r < 0 || r >= height || c < 0 || c >= width){ 90 | /** Some portion of the mask is outside the image. */ 91 | int tr = r, tc = c; 92 | if(r < 0){ 93 | tr = r+1; 94 | }else if(r == height){ 95 | tr = r-1; 96 | } 97 | if(c < 0){ 98 | tc = c+1; 99 | }else if(c == width){ 100 | tc = c-1; 101 | } 102 | buff[i] = img.getPixel(tc, tr); 103 | }else{ 104 | buff[i] = img.getPixel(c, r); 105 | } 106 | i++; 107 | } 108 | } 109 | 110 | /** Multiply mask with buff array to get the final value. */ 111 | int sa=0, sr=0, sg=0, sb=0; 112 | for(i = 0; i < 9; i++){ 113 | sa += (mask[i]*getAlphaValueFromPixelValue(buff[i]))/16; 114 | sr += (mask[i]*getRedValueFromPixelValue(buff[i]))/16; 115 | sg += (mask[i]*getGreenValueFromPixelValue(buff[i]))/16; 116 | sb += (mask[i]*getBlueValueFromPixelValue(buff[i]))/16; 117 | } 118 | 119 | /** Save result in outputPixels array. */ 120 | int p = getPixelValueFromARGBValue(sa, sr, sg, sb); 121 | outputPixels[x+y*width] = p; 122 | } 123 | } 124 | /** Write the output pixels to the image pixels */ 125 | for(int y = 0; y < height; y++){ 126 | for(int x = 0; x < width; x++){ 127 | img.setPixelToValue(x, y, outputPixels[x+y*width]); 128 | } 129 | } 130 | } 131 | 132 | }//class ends here 133 | -------------------------------------------------------------------------------- /src/imageFX/Intensity.java: -------------------------------------------------------------------------------- 1 | package imageFX; 2 | /** 3 | * File: Intensity.java 4 | * 5 | * Description: 6 | * This will find max and min intensity of the image. 7 | * 8 | * @author Yusuf Shakeel 9 | * @version 1.0 10 | * date: 06-05-2014 tue 11 | * 12 | * www.github.com/yusufshakeel/Java-Image-Processing-Project 13 | * 14 | * The MIT License (MIT) 15 | * Copyright (c) 2014 Yusuf Shakeel 16 | * 17 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 18 | * this software and associated documentation files (the "Software"), to deal in 19 | * the Software without restriction, including without limitation the rights to 20 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 21 | * the Software, and to permit persons to whom the Software is furnished to do so, 22 | * subject to the following conditions 23 | * 24 | * The above copyright notice and this permission notice shall be included in all 25 | * copies or substantial portions of the Software. 26 | * 27 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 28 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 29 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 30 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 31 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 32 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 33 | */ 34 | public class Intensity { 35 | 36 | ///////////////////////////// GRAYSCALE IMAGE ////////////////////////////// 37 | 38 | /** 39 | * This will return the maximum intensity of the grayscale image img. 40 | * 41 | * @param img The grayscale image. 42 | * @return maximum intensity. 43 | */ 44 | public static int grayscale_getMax(MyImage img){ 45 | int maxIntensity = 0; 46 | 47 | //image dimension 48 | int width = img.getImageWidth(); 49 | int height = img.getImageHeight(); 50 | 51 | //for grayscale image RGB value is same. So considering RED value. 52 | for(int y = 0; y < height; y++){ 53 | for(int x = 0; x < width; x++){ 54 | int r = img.getRed(x, y); 55 | if(r > maxIntensity){ 56 | maxIntensity = r; 57 | } 58 | } 59 | } 60 | return maxIntensity; 61 | } 62 | 63 | /** 64 | * This will return the minimum intensity of the grayscale image img. 65 | * 66 | * @param img The grayscale image. 67 | * @return minimum intensity. 68 | */ 69 | public static int grayscale_getMin(MyImage img){ 70 | int minIntensity = 255; 71 | 72 | //image dimension 73 | int width = img.getImageWidth(); 74 | int height = img.getImageHeight(); 75 | 76 | //for grayscale image RGB value is same. So considering RED value. 77 | for(int y = 0; y < height; y++){ 78 | for(int x = 0; x < width; x++){ 79 | int r = img.getRed(x, y); 80 | if(r < minIntensity){ 81 | minIntensity = r; 82 | } 83 | } 84 | } 85 | return minIntensity; 86 | } 87 | 88 | ///////////////////////////// RED IMAGE //////////////////////////////////// 89 | 90 | /** 91 | * This will return the maximum intensity of the RED image img. 92 | * 93 | * @param img The RED image. 94 | * @return maximum intensity. 95 | */ 96 | public static int red_getMax(MyImage img){ 97 | int maxIntensity = 0; 98 | 99 | //image dimension 100 | int width = img.getImageWidth(); 101 | int height = img.getImageHeight(); 102 | 103 | for(int y = 0; y < height; y++){ 104 | for(int x = 0; x < width; x++){ 105 | int r = img.getRed(x, y); 106 | if(r > maxIntensity){ 107 | maxIntensity = r; 108 | } 109 | } 110 | } 111 | return maxIntensity; 112 | } 113 | 114 | /** 115 | * This will return the minimum intensity of the RED image img. 116 | * 117 | * @param img The RED image. 118 | * @return minimum intensity. 119 | */ 120 | public static int red_getMin(MyImage img){ 121 | int minIntensity = 255; 122 | 123 | //image dimension 124 | int width = img.getImageWidth(); 125 | int height = img.getImageHeight(); 126 | 127 | for(int y = 0; y < height; y++){ 128 | for(int x = 0; x < width; x++){ 129 | int r = img.getRed(x, y); 130 | if(r < minIntensity){ 131 | minIntensity = r; 132 | } 133 | } 134 | } 135 | return minIntensity; 136 | } 137 | 138 | ///////////////////////////// GREEN IMAGE ////////////////////////////////// 139 | 140 | /** 141 | * This will return the maximum intensity of the GREEN image img. 142 | * 143 | * @param img The GREEN image. 144 | * @return maximum intensity. 145 | */ 146 | public static int green_getMax(MyImage img){ 147 | int maxIntensity = 0; 148 | 149 | //image dimension 150 | int width = img.getImageWidth(); 151 | int height = img.getImageHeight(); 152 | 153 | for(int y = 0; y < height; y++){ 154 | for(int x = 0; x < width; x++){ 155 | int g = img.getGreen(x, y); 156 | if(g > maxIntensity){ 157 | maxIntensity = g; 158 | } 159 | } 160 | } 161 | return maxIntensity; 162 | } 163 | 164 | /** 165 | * This will return the minimum intensity of the GREEN image img. 166 | * 167 | * @param img The GREEN image. 168 | * @return minimum intensity. 169 | */ 170 | public static int green_getMin(MyImage img){ 171 | int minIntensity = 255; 172 | 173 | //image dimension 174 | int width = img.getImageWidth(); 175 | int height = img.getImageHeight(); 176 | 177 | for(int y = 0; y < height; y++){ 178 | for(int x = 0; x < width; x++){ 179 | int g = img.getGreen(x, y); 180 | if(g < minIntensity){ 181 | minIntensity = g; 182 | } 183 | } 184 | } 185 | return minIntensity; 186 | } 187 | 188 | ///////////////////////////// BLUE IMAGE /////////////////////////////////// 189 | 190 | /** 191 | * This will return the maximum intensity of the BLUE image img. 192 | * 193 | * @param img The BLUE image. 194 | * @return maximum intensity. 195 | */ 196 | public static int blue_getMax(MyImage img){ 197 | int maxIntensity = 0; 198 | 199 | //image dimension 200 | int width = img.getImageWidth(); 201 | int height = img.getImageHeight(); 202 | 203 | for(int y = 0; y < height; y++){ 204 | for(int x = 0; x < width; x++){ 205 | int b = img.getBlue(x, y); 206 | if(b > maxIntensity){ 207 | maxIntensity = b; 208 | } 209 | } 210 | } 211 | return maxIntensity; 212 | } 213 | 214 | /** 215 | * This will return the minimum intensity of the BLUE image img. 216 | * 217 | * @param img The BLUE image. 218 | * @return minimum intensity. 219 | */ 220 | public static int blue_getMin(MyImage img){ 221 | int minIntensity = 255; 222 | 223 | //image dimension 224 | int width = img.getImageWidth(); 225 | int height = img.getImageHeight(); 226 | 227 | for(int y = 0; y < height; y++){ 228 | for(int x = 0; x < width; x++){ 229 | int b = img.getBlue(x, y); 230 | if(b < minIntensity){ 231 | minIntensity = b; 232 | } 233 | } 234 | } 235 | return minIntensity; 236 | } 237 | 238 | ///////////////////////////// COLOR IMAGE ////////////////////////////////// 239 | 240 | /** 241 | * This will return the maximum intensity of the color image img. 242 | * 243 | * @param img The color image. 244 | * @return maximum intensity array having 3 elements for RGB. 245 | */ 246 | public static int[] color_getMax(MyImage img){ 247 | int maxIntensity[] = new int[3]; 248 | maxIntensity[0] = red_getMax(img); 249 | maxIntensity[1] = green_getMax(img); 250 | maxIntensity[2] = blue_getMax(img); 251 | return maxIntensity; 252 | } 253 | 254 | /** 255 | * This will return the minimum intensity of the color image img. 256 | * 257 | * @param img The color image. 258 | * @return minimum intensity. 259 | */ 260 | public static int[] color_getMin(MyImage img){ 261 | int minIntensity[] = new int[3]; 262 | minIntensity[0] = red_getMin(img); 263 | minIntensity[1] = green_getMin(img); 264 | minIntensity[2] = blue_getMin(img); 265 | return minIntensity; 266 | } 267 | }//class ends here 268 | -------------------------------------------------------------------------------- /src/imageFX/Mask.java: -------------------------------------------------------------------------------- 1 | package imageFX; 2 | /** 3 | * File: Mask.java 4 | * 5 | * Description: 6 | * This fill will create mask aka kernel or structuring element. 7 | * 8 | * @author Yusuf Shakeel 9 | * @version 1.0 10 | * date: 06-05-2014 tue 11 | * 12 | * www.github.com/yusufshakeel/Java-Image-Processing-Project 13 | * 14 | * The MIT License (MIT) 15 | * Copyright (c) 2014 Yusuf Shakeel 16 | * 17 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 18 | * this software and associated documentation files (the "Software"), to deal in 19 | * the Software without restriction, including without limitation the rights to 20 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 21 | * the Software, and to permit persons to whom the Software is furnished to do so, 22 | * subject to the following conditions 23 | * 24 | * The above copyright notice and this permission notice shall be included in all 25 | * copies or substantial portions of the Software. 26 | * 27 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 28 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 29 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 30 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 31 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 32 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 33 | */ 34 | public class Mask { 35 | 36 | //mask array 37 | private static int mask[]; 38 | 39 | 40 | /** 41 | * This will return a square mask [maskSize x maskSize] having all the elements set to 1. 42 | * 43 | * @param maskSize the size of the 2D array 44 | * @return 2D mask 45 | */ 46 | public static int[] allOne(int maskSize){ 47 | mask = new int[maskSize*maskSize]; 48 | java.util.Arrays.fill(mask, 1); 49 | return mask; 50 | } 51 | 52 | ///////////////////////////// CIRCLE /////////////////////////////////////// 53 | 54 | /** 55 | * This will return a square mask with circumference of the circle set to 1. 56 | * 57 | * @param diameter diameter of the circle. [An odd integer like 9, 11, 13 etc] 58 | * @return 2D mask 59 | */ 60 | public static int[] drawCircle(int diameter){ 61 | int radius = diameter/2; 62 | int mask[] = new int[diameter * diameter]; 63 | int x = 0, y = radius, p = 1 - radius; 64 | int cx = diameter/2, cy = diameter/2; 65 | 66 | while(x<=y){ 67 | //draw circumference of the circle circle 68 | mask[(cx+x)+(cy+y)*diameter] = 1; 69 | mask[(cx-x)+(cy+y)*diameter] = 1; 70 | mask[(cx+x)+(cy-y)*diameter] = 1; 71 | mask[(cx-x)+(cy-y)*diameter] = 1; 72 | mask[(cx+y)+(cy+x)*diameter] = 1; 73 | mask[(cx-y)+(cy+x)*diameter] = 1; 74 | mask[(cx+y)+(cy-x)*diameter] = 1; 75 | mask[(cx-y)+(cy-x)*diameter] = 1; 76 | 77 | x++; 78 | if(p<0){ 79 | p+=2*x+1; 80 | }else{ 81 | y--; 82 | p+=2*(x-y)+1; 83 | } 84 | } 85 | return mask; 86 | } 87 | 88 | /** 89 | * This will return a square mask with circle filled with 1. 90 | * 91 | * @param diameter diameter of the circle. [An odd integer like 9, 11, 13...] 92 | * @return 2D mask 93 | */ 94 | public static int[] fillCircle(int diameter){ 95 | int radius = diameter/2; 96 | int cx = diameter/2, cy = diameter/2; 97 | 98 | //draw circle 99 | mask = drawCircle(diameter); 100 | 101 | //fill circle 102 | floodFill(diameter, diameter, cx, cy, 0, 1); 103 | 104 | return mask; 105 | } 106 | 107 | //////////////////////////////// DIAMOND /////////////////////////////////// 108 | 109 | /** 110 | * This will return a square mask having diamond shape set to 1. 111 | * 112 | * @param width The width of the square mask. [An odd integer like 9, 11, 13 etc] 113 | * @return 2D mask 114 | */ 115 | public static int[] drawDiamond(int width){ 116 | int mask[] = new int[width * width]; 117 | int x = 0, y = width/2; 118 | int cx = width/2, cy = width/2; 119 | 120 | while(x<=y){ 121 | //draw diamond 122 | mask[(cx+x)+(cy+y)*width] = 1; 123 | mask[(cx-x)+(cy+y)*width] = 1; 124 | mask[(cx+x)+(cy-y)*width] = 1; 125 | mask[(cx-x)+(cy-y)*width] = 1; 126 | mask[(cx+y)+(cy+x)*width] = 1; 127 | mask[(cx-y)+(cy+x)*width] = 1; 128 | mask[(cx+y)+(cy-x)*width] = 1; 129 | mask[(cx-y)+(cy-x)*width] = 1; 130 | 131 | x++; 132 | y--; 133 | } 134 | return mask; 135 | } 136 | 137 | /** 138 | * This will return a square mask with filled diamond. 139 | * 140 | * @param width The width of the square mask. [An odd integer like 9, 11, 13...] 141 | * @return 2D mask 142 | */ 143 | public static int[] fillDiamond(int width){ 144 | int cx = width/2, cy = width/2; 145 | 146 | //draw diamond 147 | mask = drawDiamond(width); 148 | 149 | //fill diamond 150 | floodFill(width, width, cx, cy, 0, 1); 151 | 152 | return mask; 153 | } 154 | 155 | /** 156 | * This will return a square mask with of diamond shape with corner filled with 1. 157 | * 158 | * @param width The width of the square mask. [An odd integer like 9, 11, 13...] 159 | * @return 2D mask 160 | */ 161 | public static int[] fillDiamondCorners(int width){ 162 | int cx = width/2, cy = width/2; 163 | 164 | //draw diamond 165 | mask = drawDiamond(width); 166 | 167 | //fill diamond 168 | floodFill(width, width, cx, cy, 0, 1); 169 | 170 | //invert 171 | for(int y = 0; y < width; y++){ 172 | for(int x = 0; x < width; x++){ 173 | mask[x+y*width] = (mask[x+y*width]==1)?0:1; 174 | } 175 | } 176 | 177 | return mask; 178 | } 179 | 180 | ///////////////////////////// FLOOD FILL /////////////////////////////////// 181 | 182 | /** 183 | * This method will floodfill the image. 184 | * 185 | * @param width the width of the image 186 | * @param height the height of the image 187 | * @param cx x coordinate of the center of the image 188 | * @param cy y coordinate of the center of the image 189 | * @param oldColor the color to be replaced 190 | * @param newColor the color that will replace the oldColor 191 | */ 192 | private static void floodFill(int width, int height, int cx, int cy, int oldColor, int newColor){ 193 | if(cx<0 || cx>=width || cy<0 || cy>=height){ 194 | return; 195 | } 196 | 197 | if(mask[cx+cy*width] == oldColor){ 198 | mask[cx+cy*width] = newColor; 199 | floodFill(width, height, cx+1, cy, oldColor, newColor); 200 | floodFill(width, height, cx, cy+1, oldColor, newColor); 201 | floodFill(width, height, cx-1, cy, oldColor, newColor); 202 | floodFill(width, height, cx, cy-1, oldColor, newColor); 203 | } 204 | } 205 | }//class ends here 206 | -------------------------------------------------------------------------------- /src/imageFX/filter/Spatial.java: -------------------------------------------------------------------------------- 1 | package imageFX.filter; 2 | import imageFX.ImageFX; 3 | import imageFX.MyImage; 4 | 5 | /** 6 | * File: Spatial.java 7 | * 8 | * Description: 9 | * This will perform spatial - conservative smoothing. 10 | * It is a noise reduction technique. 11 | * 12 | * @author Yusuf Shakeel 13 | * @version 1.0 14 | * Date: 25-04-2014 fri 15 | * 16 | * www.github.com/yusufshakeel/Java-Image-Processing-Project 17 | * 18 | * The MIT License (MIT) 19 | * Copyright (c) 2014 Yusuf Shakeel 20 | * 21 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 22 | * this software and associated documentation files (the "Software"), to deal in 23 | * the Software without restriction, including without limitation the rights to 24 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 25 | * the Software, and to permit persons to whom the Software is furnished to do so, 26 | * subject to the following conditions 27 | * 28 | * The above copyright notice and this permission notice shall be included in all 29 | * copies or substantial portions of the Software. 30 | * 31 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 32 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 33 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 34 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 35 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 36 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 37 | */ 38 | public class Spatial { 39 | 40 | /** 41 | * This method is used to perform spatial filtering on the image object passed. 42 | * Also known as Conservative smoothing and used for noise reduction. 43 | * 44 | * @param img The image object passed on which spatial filtering is performed. 45 | * @param maskSize - The size of the mask is an odd integer like 3, 5, 7 … etc. 46 | */ 47 | public static void spatialFilter_RGB(MyImage img, int maskSize){ 48 | 49 | /** 50 | * This array will store the output of the spatial filter operation which will 51 | * be later written back to the original image pixels. 52 | */ 53 | int outputPixels[] = new int[img.getImageTotalPixels()]; 54 | 55 | //image dimension 56 | int width = img.getImageWidth(); 57 | int height = img.getImageHeight(); 58 | 59 | /** 60 | * red, green and blue are a 2D square of odd size like 3x3, 5x5, 7x7, ... 61 | * For simplicity storing it into 1D array. 62 | */ 63 | int red[], green[], blue[]; 64 | 65 | /** spatial Filter operation */ 66 | for(int y = 0; y < height; y++){ 67 | for(int x = 0; x < width; x++){ 68 | red = new int[maskSize * maskSize]; 69 | green = new int [maskSize * maskSize]; 70 | blue = new int [maskSize * maskSize]; 71 | int count = 0; 72 | for(int r = y - (maskSize / 2); r <= y + (maskSize / 2); r++){ 73 | for(int c = x - (maskSize / 2); c <= x + (maskSize / 2); c++){ 74 | if(r < 0 || r >= height || c < 0 || c >= width){ 75 | /** Some portion of the mask is outside the image. */ 76 | continue; 77 | }else if(x == c && y == r){ 78 | /** pixel below the center of the mask */ 79 | continue; 80 | }else{ 81 | red[count] = img.getRed(c, r); 82 | green[count] = img.getGreen(c, r); 83 | blue[count] = img.getBlue(c, r); 84 | count++; 85 | } 86 | } 87 | } 88 | 89 | /** sort red, green, blue array */ 90 | java.util.Arrays.sort(red); 91 | java.util.Arrays.sort(green); 92 | java.util.Arrays.sort(blue); 93 | 94 | //RGB value of image pixel 95 | int pixelRED = img.getRed(x, y); 96 | int pixelGREEN = img.getGreen(x, y); 97 | int pixelBLUE = img.getBlue(x, y); 98 | 99 | //final RGB value 100 | int fRED, fGREEN, fBLUE; 101 | 102 | //compute final RGB value 103 | if(pixelRED > red[maskSize*maskSize - 1]){ 104 | fRED = red[maskSize*maskSize - 1]; 105 | }else if(pixelRED < red[maskSize*maskSize - count]){ 106 | fRED = red[maskSize*maskSize - count]; 107 | }else{ 108 | fRED = pixelRED; 109 | } 110 | 111 | if(pixelGREEN > green[maskSize*maskSize - 1]){ 112 | fGREEN = green[maskSize*maskSize - 1]; 113 | }else if(pixelGREEN < green[maskSize*maskSize - count]){ 114 | fGREEN = green[maskSize*maskSize - count]; 115 | }else{ 116 | fGREEN = pixelGREEN; 117 | } 118 | 119 | if(pixelBLUE > blue[maskSize*maskSize - 1]){ 120 | fBLUE = blue[maskSize*maskSize - 1]; 121 | }else if(pixelBLUE < blue[maskSize*maskSize - count]){ 122 | fBLUE = blue[maskSize*maskSize - count]; 123 | }else{ 124 | fBLUE = pixelBLUE; 125 | } 126 | 127 | /** save spatial value in outputPixels array */ 128 | int p = ImageFX.getPixelValueFromARGBValue(255, fRED, fGREEN, fBLUE); 129 | outputPixels[x+y*width] = p; 130 | } 131 | } 132 | /** Write the output pixels to the image pixels */ 133 | for(int y = 0; y < height; y++){ 134 | for(int x = 0; x < width; x++){ 135 | img.setPixelToValue(x, y, outputPixels[x+y*width]); 136 | } 137 | } 138 | } 139 | }//class ends here 140 | -------------------------------------------------------------------------------- /src/imageFX/math/Add.java: -------------------------------------------------------------------------------- 1 | package imageFX.math; 2 | import imageFX.MyImage; 3 | 4 | /** 5 | * File: Add.java 6 | * 7 | * Description: 8 | * To perform addition of image pixels. 9 | * 10 | * @author Yusuf Shakeel 11 | * @version 1.0 12 | * Date: 25-04-2014 fri 13 | * 14 | * www.github.com/yusufshakeel/Java-Image-Processing-Project 15 | * 16 | * The MIT License (MIT) 17 | * Copyright (c) 2014 Yusuf Shakeel 18 | * 19 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 20 | * this software and associated documentation files (the "Software"), to deal in 21 | * the Software without restriction, including without limitation the rights to 22 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 23 | * the Software, and to permit persons to whom the Software is furnished to do so, 24 | * subject to the following conditions 25 | * 26 | * The above copyright notice and this permission notice shall be included in all 27 | * copies or substantial portions of the Software. 28 | * 29 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 30 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 31 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 32 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 33 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 34 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 35 | */ 36 | public class Add { 37 | 38 | /////////////////////////////// BINARY IMAGE //////////////////////////////// 39 | 40 | /** 41 | * This method will add the pixels of the binary image. 42 | * It takes two equal size binary images and adds their pixels. 43 | * The result of addition is saved in resultImg which is also of the same size. 44 | * 45 | * @param sourceImg1 The first image. 46 | * @param sourceImg2 The second image. 47 | * @param resultImg This will hold the resultant image after addition of image1 and image2. 48 | */ 49 | public static void binaryImage(MyImage sourceImg1, MyImage sourceImg2, MyImage resultImg){ 50 | /** 51 | * Note grayscale and binary image pixel addition is almost same. 52 | * So, calling grayscaleImage() method 53 | */ 54 | grayscaleImage(sourceImg1, sourceImg2, resultImg); 55 | } 56 | 57 | /** 58 | * This method will add the pixels of the binary image. 59 | * It takes a binary images and adds its pixel with a constant value C. 60 | * The result of addition is saved in resultImg which is of same size as sourceImage. 61 | * 62 | * @param sourceImg1 The first image. 63 | * @param C The constant to add. [0-255] 64 | * @param resultImg This will hold the resultant image after addition of image1 and image2. 65 | */ 66 | public static void binaryImage(MyImage sourceImg1, int C, MyImage resultImg){ 67 | /** 68 | * Note grayscale and binary image pixel addition is almost same. 69 | * So, calling grayscaleImage() method 70 | */ 71 | grayscaleImage(sourceImg1, C, resultImg); 72 | } 73 | 74 | /////////////////////////////// GRAYSCALE IMAGE //////////////////////////// 75 | 76 | /** 77 | * This method will add the pixels of the grayscale image. 78 | * It takes two equal size grayscale images and adds their pixels. 79 | * The result of addition is saved in resultImg which is also of the same size. 80 | * 81 | * @param sourceImg1 The first image. 82 | * @param sourceImg2 The second image. 83 | * @param resultImg This will hold the resultant image after addition of image1 and image2. 84 | */ 85 | public static void grayscaleImage(MyImage sourceImg1, MyImage sourceImg2, MyImage resultImg){ 86 | 87 | //image dimension - common for all the three images 88 | int width = sourceImg1.getImageWidth(); 89 | int height = sourceImg1.getImageHeight(); 90 | 91 | //variable 92 | int p, result; 93 | 94 | /** 95 | * Add pixels 96 | * Grayscale image will have same value for RGB so take any one component. 97 | */ 98 | for(int y = 0; y < height; y++){ 99 | for(int x = 0; x < width; x++){ 100 | p = sourceImg1.getBlue(x, y) + sourceImg2.getBlue(x, y); 101 | result = (p>255)?255:p; 102 | resultImg.setPixel(x, y, 255, result, result, result); 103 | } 104 | } 105 | } 106 | 107 | /** 108 | * This method will add the pixels of the grayscale image. 109 | * It takes a grayscale images and adds its pixel with a constant value C. 110 | * The result of addition is saved in resultImg which is of the size of sourceImage. 111 | * 112 | * @param sourceImg1 The first image. 113 | * @param C constant number to add. [0-255] 114 | * @param resultImg This will hold the resultant image after addition of image1 and image2. 115 | */ 116 | public static void grayscaleImage(MyImage sourceImg1, int C, MyImage resultImg){ 117 | 118 | //image dimension - common for the two images 119 | int width = sourceImg1.getImageWidth(); 120 | int height = sourceImg1.getImageHeight(); 121 | 122 | //variable 123 | int p, result; 124 | 125 | /** 126 | * Add pixels 127 | * Grayscale image will have same value for RGB so take any one component. 128 | */ 129 | for(int y = 0; y < height; y++){ 130 | for(int x = 0; x < width; x++){ 131 | p = sourceImg1.getBlue(x, y) + C; 132 | result = (p>255)?255:p; 133 | resultImg.setPixel(x, y, 255, result, result, result); 134 | } 135 | } 136 | } 137 | 138 | /////////////////////////////// COLOR IMAGE //////////////////////////////// 139 | 140 | /** 141 | * This method will add the pixels of the color image. 142 | * It takes two equal size color images and adds their pixels. 143 | * The result of addition is saved in resultImg which is also of the same size. 144 | * 145 | * @param sourceImg1 The first image. 146 | * @param sourceImg2 The second image. 147 | * @param resultImg This will hold the resultant image after addition of image1 and image2. 148 | */ 149 | public static void colorImage(MyImage sourceImg1, MyImage sourceImg2, MyImage resultImg){ 150 | 151 | //image dimension - common for all the three images 152 | int width = sourceImg1.getImageWidth(); 153 | int height = sourceImg1.getImageHeight(); 154 | 155 | //variable 156 | int pRED, pGREEN, pBLUE, rRED, rGREEN, rBLUE; 157 | 158 | /** 159 | * Add pixels 160 | */ 161 | for(int y = 0; y < height; y++){ 162 | for(int x = 0; x < width; x++){ 163 | //add the RGB components of the two source image 164 | pRED = sourceImg1.getRed(x, y) + sourceImg2.getRed(x, y); 165 | pGREEN = sourceImg1.getGreen(x, y) + sourceImg2.getGreen(x, y); 166 | pBLUE = sourceImg1.getBlue(x, y) + sourceImg2.getBlue(x, y); 167 | 168 | //find result 169 | rRED = (pRED>255)?255:pRED; 170 | rGREEN = (pGREEN>255)?255:pGREEN; 171 | rBLUE = (pBLUE>255)?255:pBLUE; 172 | 173 | //save result 174 | resultImg.setPixel(x, y, 255, rRED, rGREEN, rBLUE); 175 | } 176 | } 177 | } 178 | 179 | /** 180 | * This method will add the pixels of the color image. 181 | * It takes a color images and adds its pixel with a constant value C. 182 | * The result of addition is saved in resultImg which is of the size of sourceImage. 183 | * 184 | * @param sourceImg1 The first image. 185 | * @param C The constant value to add. [0-255] 186 | * @param resultImg This will hold the resultant image after addition of image1 and image2. 187 | */ 188 | public static void colorImage(MyImage sourceImg1, int C, MyImage resultImg){ 189 | 190 | //image dimension - common for all the three images 191 | int width = sourceImg1.getImageWidth(); 192 | int height = sourceImg1.getImageHeight(); 193 | 194 | //variable 195 | int pRED, pGREEN, pBLUE, rRED, rGREEN, rBLUE; 196 | 197 | /** 198 | * Add pixels 199 | */ 200 | for(int y = 0; y < height; y++){ 201 | for(int x = 0; x < width; x++){ 202 | //add the RGB components of the two source image 203 | pRED = sourceImg1.getRed(x, y) + C; 204 | pGREEN = sourceImg1.getGreen(x, y) + C; 205 | pBLUE = sourceImg1.getBlue(x, y) + C; 206 | 207 | //find result 208 | rRED = (pRED>255)?255:pRED; 209 | rGREEN = (pGREEN>255)?255:pGREEN; 210 | rBLUE = (pBLUE>255)?255:pBLUE; 211 | 212 | //save result 213 | resultImg.setPixel(x, y, 255, rRED, rGREEN, rBLUE); 214 | } 215 | } 216 | } 217 | }//class ends here 218 | -------------------------------------------------------------------------------- /src/imageFX/math/Blend.java: -------------------------------------------------------------------------------- 1 | package imageFX.math; 2 | import imageFX.MyImage; 3 | 4 | /** 5 | * File: Blend.java 6 | * 7 | * Description: 8 | * To perform blending of image pixels. 9 | * 10 | * @author Yusuf Shakeel 11 | * @version 1.0 12 | * Date: 25-04-2014 fri 13 | * 14 | * www.github.com/yusufshakeel/Java-Image-Processing-Project 15 | * 16 | * The MIT License (MIT) 17 | * Copyright (c) 2014 Yusuf Shakeel 18 | * 19 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 20 | * this software and associated documentation files (the "Software"), to deal in 21 | * the Software without restriction, including without limitation the rights to 22 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 23 | * the Software, and to permit persons to whom the Software is furnished to do so, 24 | * subject to the following conditions 25 | * 26 | * The above copyright notice and this permission notice shall be included in all 27 | * copies or substantial portions of the Software. 28 | * 29 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 30 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 31 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 32 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 33 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 34 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 35 | */ 36 | 37 | public class Blend { 38 | 39 | /////////////////////////////// BINARY IMAGE //////////////////////////////// 40 | 41 | /** 42 | * This method will blend the pixels of the binary image. 43 | * It takes two equal size binary images and blend their pixels. 44 | * The result of blend is saved in resultImg which is also of the same size. 45 | * 46 | * @param sourceImg1 The first image. 47 | * @param sourceImg2 The second image. 48 | * @param resultImg This will hold the resultant image after blend of image1 and image2. 49 | * @param blendRatio The blend ratio. 50 | */ 51 | public static void binaryImage(MyImage sourceImg1, MyImage sourceImg2, MyImage resultImg, float blendRatio){ 52 | /** 53 | * Note grayscale and binary image pixel blend is almost same. 54 | * So, calling grayscaleImage() method 55 | */ 56 | grayscaleImage(sourceImg1, sourceImg2, resultImg, blendRatio); 57 | } 58 | 59 | /////////////////////////////// GRAYSCALE IMAGE //////////////////////////// 60 | 61 | /** 62 | * This method will blend the pixels of the grayscale image. 63 | * It takes two equal size grayscale images and blend their pixels. 64 | * The result of blend is saved in resultImg which is also of the same size. 65 | * 66 | * @param sourceImg1 The first image. 67 | * @param sourceImg2 The second image. 68 | * @param resultImg This will hold the resultant image after blend of image1 and image2. 69 | * @param blendRatio The blend ratio. 70 | */ 71 | public static void grayscaleImage(MyImage sourceImg1, MyImage sourceImg2, MyImage resultImg, float blendRatio){ 72 | 73 | //image dimension - common for all the three images 74 | int width = sourceImg1.getImageWidth(); 75 | int height = sourceImg1.getImageHeight(); 76 | 77 | //variable 78 | int result; 79 | 80 | /** 81 | * blend pixels 82 | * Grayscale image will have same value for RGB so take any one component. 83 | */ 84 | for(int y = 0; y < height; y++){ 85 | for(int x = 0; x < width; x++){ 86 | result = (int)((blendRatio*sourceImg1.getBlue(x, y)) + ((1-blendRatio)*sourceImg2.getBlue(x, y))); 87 | if(result > 255){ 88 | result = 255; 89 | }else if(result < 0){ 90 | result = 0; 91 | } 92 | resultImg.setPixel(x, y, 255, result, result, result); 93 | } 94 | } 95 | } 96 | 97 | /////////////////////////////// COLOR IMAGE //////////////////////////////// 98 | 99 | /** 100 | * This method will blend the pixels of the color image. 101 | * It takes two equal size color images and blend their pixels. 102 | * The result of blend is saved in resultImg which is also of the same size. 103 | * 104 | * @param sourceImg1 The first image. 105 | * @param sourceImg2 The second image. 106 | * @param resultImg This will hold the resultant image after blend of image1 and image2. 107 | * @param blendRatio The blend ratio. 108 | */ 109 | public static void colorImage(MyImage sourceImg1, MyImage sourceImg2, MyImage resultImg, float blendRatio){ 110 | 111 | //image dimension - common for all the three images 112 | int width = sourceImg1.getImageWidth(); 113 | int height = sourceImg1.getImageHeight(); 114 | 115 | //variable 116 | int rRED, rGREEN, rBLUE; 117 | 118 | /** 119 | * blend pixels 120 | */ 121 | for(int y = 0; y < height; y++){ 122 | for(int x = 0; x < width; x++){ 123 | //blend the RGB components of the two source image 124 | rRED = (int)((blendRatio*sourceImg1.getRed(x, y)) + ((1-blendRatio)*sourceImg2.getRed(x, y))); 125 | rGREEN = (int)((blendRatio*sourceImg1.getGreen(x, y)) + ((1-blendRatio)*sourceImg2.getGreen(x, y))); 126 | rBLUE = (int)((blendRatio*sourceImg1.getBlue(x, y)) + ((1-blendRatio)*sourceImg2.getBlue(x, y))); 127 | 128 | if(rRED>255){ 129 | rRED = 255; 130 | }else if(rRED<0){ 131 | rRED = 0; 132 | } 133 | 134 | if(rGREEN>255){ 135 | rGREEN = 255; 136 | }else if(rGREEN<0){ 137 | rGREEN = 0; 138 | } 139 | 140 | if(rBLUE>255){ 141 | rBLUE = 255; 142 | }else if(rBLUE<0){ 143 | rBLUE = 0; 144 | } 145 | 146 | //save result 147 | resultImg.setPixel(x, y, 255, rRED, rGREEN, rBLUE); 148 | } 149 | } 150 | } 151 | }//class ends here 152 | -------------------------------------------------------------------------------- /src/imageFX/math/Divide.java: -------------------------------------------------------------------------------- 1 | package imageFX.math; 2 | import imageFX.MyImage; 3 | 4 | /** 5 | * File: Divide.java 6 | * 7 | * Description: 8 | * To perform division of image pixels. 9 | * 10 | * @author Yusuf Shakeel 11 | * @version 1.0 12 | * Date: 25-04-2014 fri 13 | * 14 | * www.github.com/yusufshakeel/Java-Image-Processing-Project 15 | * 16 | * The MIT License (MIT) 17 | * Copyright (c) 2014 Yusuf Shakeel 18 | * 19 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 20 | * this software and associated documentation files (the "Software"), to deal in 21 | * the Software without restriction, including without limitation the rights to 22 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 23 | * the Software, and to permit persons to whom the Software is furnished to do so, 24 | * subject to the following conditions 25 | * 26 | * The above copyright notice and this permission notice shall be included in all 27 | * copies or substantial portions of the Software. 28 | * 29 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 30 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 31 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 32 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 33 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 34 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 35 | */ 36 | public class Divide { 37 | 38 | /////////////////////////////// BINARY IMAGE //////////////////////////////// 39 | 40 | /** 41 | * This method will divide the pixels of the binary image. 42 | * It takes two equal size binary images and divides their pixels. 43 | * The result of division is saved in resultImg which is also of the same size. 44 | * 45 | * @param sourceImg1 The first image. 46 | * @param sourceImg2 The second image. 47 | * @param resultImg This will hold the resultant image after division of image1 and image2. 48 | */ 49 | public static void binaryImage(MyImage sourceImg1, MyImage sourceImg2, MyImage resultImg){ 50 | /** 51 | * Note grayscale and binary image pixel division is almost same. 52 | * So, calling grayscaleImage() method 53 | */ 54 | grayscaleImage(sourceImg1, sourceImg2, resultImg); 55 | } 56 | 57 | /** 58 | * This method will divide the pixels of the binary image. 59 | * It takes a binary images and divides its pixel with a constant value C. 60 | * The result of division is saved in resultImg which is of same size as sourceImage. 61 | * 62 | * @param sourceImg1 The first image. 63 | * @param C The constant to add. [0-255] 64 | * @param resultImg This will hold the resultant image after division of image1 and image2. 65 | */ 66 | public static void binaryImage(MyImage sourceImg1, int C, MyImage resultImg){ 67 | /** 68 | * Note grayscale and binary image pixel division is almost same. 69 | * So, calling grayscaleImage() method 70 | */ 71 | grayscaleImage(sourceImg1, C, resultImg); 72 | } 73 | 74 | /////////////////////////////// GRAYSCALE IMAGE //////////////////////////// 75 | 76 | /** 77 | * This method will division the pixels of the grayscale image. 78 | * It takes two equal size grayscale images and divides their pixels. 79 | * The result of divisions is saved in resultImg which is also of the same size. 80 | * 81 | * @param sourceImg1 The first image. 82 | * @param sourceImg2 The second image. 83 | * @param resultImg This will hold the resultant image after divisions of image1 and image2. 84 | */ 85 | public static void grayscaleImage(MyImage sourceImg1, MyImage sourceImg2, MyImage resultImg){ 86 | 87 | //image dimension - common for all the three images 88 | int width = sourceImg1.getImageWidth(); 89 | int height = sourceImg1.getImageHeight(); 90 | 91 | //variable 92 | int result; 93 | 94 | /** 95 | * divide pixels 96 | * Grayscale image will have same value for RGB so take any one component. 97 | */ 98 | for(int y = 0; y < height; y++){ 99 | for(int x = 0; x < width; x++){ 100 | if(sourceImg2.getBlue(x, y) > 0){ 101 | result = sourceImg1.getBlue(x, y) / sourceImg2.getBlue(x, y); 102 | }else{ 103 | result = 0; 104 | } 105 | resultImg.setPixel(x, y, 255, result, result, result); 106 | } 107 | } 108 | } 109 | 110 | /** 111 | * This method will divide the pixels of the grayscale image. 112 | * It takes a grayscale images and divides its pixel with a constant value C. 113 | * The result of division is saved in resultImg which is of the size of sourceImage. 114 | * 115 | * @param sourceImg1 The first image. 116 | * @param C constant number to add. [1-255] 117 | * @param resultImg This will hold the resultant image after divisions of image1 and image2. 118 | */ 119 | public static void grayscaleImage(MyImage sourceImg1, int C, MyImage resultImg){ 120 | 121 | //image dimension - common for the two images 122 | int width = sourceImg1.getImageWidth(); 123 | int height = sourceImg1.getImageHeight(); 124 | 125 | //variable 126 | int result; 127 | 128 | /** 129 | * divide pixels 130 | * Grayscale image will have same value for RGB so take any one component. 131 | */ 132 | for(int y = 0; y < height; y++){ 133 | for(int x = 0; x < width; x++){ 134 | result = sourceImg1.getBlue(x, y) / C; 135 | resultImg.setPixel(x, y, 255, result, result, result); 136 | } 137 | } 138 | } 139 | 140 | /////////////////////////////// COLOR IMAGE //////////////////////////////// 141 | 142 | /** 143 | * This method will divide the pixels of the color image. 144 | * It takes two equal size color images and divides their pixels. 145 | * The result of divisions is saved in resultImg which is also of the same size. 146 | * 147 | * @param sourceImg1 The first image. 148 | * @param sourceImg2 The second image. 149 | * @param resultImg This will hold the resultant image after divisions of image1 and image2. 150 | */ 151 | public static void colorImage(MyImage sourceImg1, MyImage sourceImg2, MyImage resultImg){ 152 | 153 | //image dimension - common for all the three images 154 | int width = sourceImg1.getImageWidth(); 155 | int height = sourceImg1.getImageHeight(); 156 | 157 | //variable 158 | int rRED, rGREEN, rBLUE; 159 | 160 | /** 161 | * divide pixels 162 | */ 163 | for(int y = 0; y < height; y++){ 164 | for(int x = 0; x < width; x++){ 165 | //divide 166 | if(sourceImg2.getRed(x, y) > 0){ 167 | rRED = sourceImg1.getRed(x, y) / sourceImg2.getRed(x, y); 168 | }else{ 169 | rRED = 0; 170 | } 171 | 172 | if(sourceImg2.getGreen(x, y) > 0){ 173 | rGREEN = sourceImg1.getGreen(x, y) / sourceImg2.getGreen(x, y); 174 | }else{ 175 | rGREEN = 0; 176 | } 177 | 178 | if(sourceImg2.getBlue(x, y) > 0){ 179 | rBLUE = sourceImg1.getBlue(x, y) / sourceImg2.getBlue(x, y); 180 | }else{ 181 | rBLUE = 0; 182 | } 183 | 184 | //save result 185 | resultImg.setPixel(x, y, 255, rRED, rGREEN, rBLUE); 186 | } 187 | } 188 | } 189 | 190 | /** 191 | * This method will divide the pixels of the color image. 192 | * It takes a color images and divides its pixel with a constant value C. 193 | * The result of division is saved in resultImg which is of the size of sourceImage. 194 | * 195 | * @param sourceImg1 The first image. 196 | * @param C The constant value to add. [1-255] 197 | * @param resultImg This will hold the resultant image after division of image1 and image2. 198 | */ 199 | public static void colorImage(MyImage sourceImg1, int C, MyImage resultImg){ 200 | 201 | //image dimension - common for all the three images 202 | int width = sourceImg1.getImageWidth(); 203 | int height = sourceImg1.getImageHeight(); 204 | 205 | //variable 206 | int rRED, rGREEN, rBLUE; 207 | 208 | /** 209 | * divide pixels 210 | */ 211 | for(int y = 0; y < height; y++){ 212 | for(int x = 0; x < width; x++){ 213 | //divide 214 | rRED = sourceImg1.getRed(x, y) / C; 215 | rGREEN = sourceImg1.getGreen(x, y) / C; 216 | rBLUE = sourceImg1.getBlue(x, y) / C; 217 | 218 | //save result 219 | resultImg.setPixel(x, y, 255, rRED, rGREEN, rBLUE); 220 | } 221 | } 222 | } 223 | }//class ends here 224 | -------------------------------------------------------------------------------- /src/imageFX/math/Multiply.java: -------------------------------------------------------------------------------- 1 | package imageFX.math; 2 | import imageFX.MyImage; 3 | 4 | /** 5 | * File: Multiply.java 6 | * 7 | * Description: 8 | * To perform multiplication of image pixels. 9 | * 10 | * @author Yusuf Shakeel 11 | * @version 1.0 12 | * Date: 25-04-2014 fri 13 | * 14 | * www.github.com/yusufshakeel/Java-Image-Processing-Project 15 | * 16 | * The MIT License (MIT) 17 | * Copyright (c) 2014 Yusuf Shakeel 18 | * 19 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 20 | * this software and associated documentation files (the "Software"), to deal in 21 | * the Software without restriction, including without limitation the rights to 22 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 23 | * the Software, and to permit persons to whom the Software is furnished to do so, 24 | * subject to the following conditions 25 | * 26 | * The above copyright notice and this permission notice shall be included in all 27 | * copies or substantial portions of the Software. 28 | * 29 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 30 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 31 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 32 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 33 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 34 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 35 | */ 36 | public class Multiply { 37 | 38 | /////////////////////////////// BINARY IMAGE //////////////////////////////// 39 | 40 | /** 41 | * This method will multiply the pixels of the binary image. 42 | * It takes two equal size binary images and multiply their pixels. 43 | * The result of multiplication is saved in resultImg which is also of the same size. 44 | * 45 | * @param sourceImg1 The first image. 46 | * @param sourceImg2 The second image. 47 | * @param resultImg This will hold the resultant image after multiplication of image1 and image2. 48 | */ 49 | public static void binaryImage(MyImage sourceImg1, MyImage sourceImg2, MyImage resultImg){ 50 | /** 51 | * Note grayscale and binary image pixel multiplication is almost same. 52 | * So, calling grayscaleImage() method 53 | */ 54 | grayscaleImage(sourceImg1, sourceImg2, resultImg); 55 | } 56 | 57 | /** 58 | * This method will multiply the pixels of the binary image. 59 | * It takes a binary images and multiply its pixel with a constant value C. 60 | * The result of multiplication is saved in resultImg which is of same size as sourceImage. 61 | * 62 | * @param sourceImg1 The first image. 63 | * @param C The constant to add. [0-255] 64 | * @param resultImg This will hold the resultant image after multiplication of image1 and image2. 65 | */ 66 | public static void binaryImage(MyImage sourceImg1, int C, MyImage resultImg){ 67 | /** 68 | * Note grayscale and binary image pixel multiplication is almost same. 69 | * So, calling grayscaleImage() method 70 | */ 71 | grayscaleImage(sourceImg1, C, resultImg); 72 | } 73 | 74 | /////////////////////////////// GRAYSCALE IMAGE //////////////////////////// 75 | 76 | /** 77 | * This method will multiply the pixels of the grayscale image. 78 | * It takes two equal size grayscale images and multiply their pixels. 79 | * The result of multiplication is saved in resultImg which is also of the same size. 80 | * 81 | * @param sourceImg1 The first image. 82 | * @param sourceImg2 The second image. 83 | * @param resultImg This will hold the resultant image after multiplication of image1 and image2. 84 | */ 85 | public static void grayscaleImage(MyImage sourceImg1, MyImage sourceImg2, MyImage resultImg){ 86 | 87 | //image dimension - common for all the three images 88 | int width = sourceImg1.getImageWidth(); 89 | int height = sourceImg1.getImageHeight(); 90 | 91 | //variable 92 | int p, result; 93 | 94 | /** 95 | * multiply pixels 96 | * Grayscale image will have same value for RGB so take any one component. 97 | */ 98 | for(int y = 0; y < height; y++){ 99 | for(int x = 0; x < width; x++){ 100 | p = sourceImg1.getBlue(x, y) * sourceImg2.getBlue(x, y); 101 | result = (p>255)?255:p; 102 | resultImg.setPixel(x, y, 255, result, result, result); 103 | } 104 | } 105 | } 106 | 107 | /** 108 | * This method will multiply the pixels of the grayscale image. 109 | * It takes a grayscale images and multiply its pixel with a constant value C. 110 | * The result of multiplication is saved in resultImg which is of the size of sourceImage. 111 | * 112 | * @param sourceImg1 The first image. 113 | * @param C constant number to add. [0-255] 114 | * @param resultImg This will hold the resultant image after multiplication of image1 and image2. 115 | */ 116 | public static void grayscaleImage(MyImage sourceImg1, int C, MyImage resultImg){ 117 | 118 | //image dimension - common for the two images 119 | int width = sourceImg1.getImageWidth(); 120 | int height = sourceImg1.getImageHeight(); 121 | 122 | //variable 123 | int p, result; 124 | 125 | /** 126 | * multiplication pixels 127 | * Grayscale image will have same value for RGB so take any one component. 128 | */ 129 | for(int y = 0; y < height; y++){ 130 | for(int x = 0; x < width; x++){ 131 | p = sourceImg1.getBlue(x, y) * C; 132 | result = (p>255)?255:p; 133 | resultImg.setPixel(x, y, 255, result, result, result); 134 | } 135 | } 136 | } 137 | 138 | /////////////////////////////// COLOR IMAGE //////////////////////////////// 139 | 140 | /** 141 | * This method will multiply the pixels of the color image. 142 | * It takes two equal size color images and multiply their pixels. 143 | * The result of multiplication is saved in resultImg which is also of the same size. 144 | * 145 | * @param sourceImg1 The first image. 146 | * @param sourceImg2 The second image. 147 | * @param resultImg This will hold the resultant image after multiplication of image1 and image2. 148 | */ 149 | public static void colorImage(MyImage sourceImg1, MyImage sourceImg2, MyImage resultImg){ 150 | 151 | //image dimension - common for all the three images 152 | int width = sourceImg1.getImageWidth(); 153 | int height = sourceImg1.getImageHeight(); 154 | 155 | //variable 156 | int pRED, pGREEN, pBLUE, rRED, rGREEN, rBLUE; 157 | 158 | /** 159 | * multiply pixels 160 | */ 161 | for(int y = 0; y < height; y++){ 162 | for(int x = 0; x < width; x++){ 163 | //multiply the RGB components of the two source image 164 | pRED = sourceImg1.getRed(x, y) * sourceImg2.getRed(x, y); 165 | pGREEN = sourceImg1.getGreen(x, y) * sourceImg2.getGreen(x, y); 166 | pBLUE = sourceImg1.getBlue(x, y) * sourceImg2.getBlue(x, y); 167 | 168 | //find result 169 | rRED = (pRED>255)?255:pRED; 170 | rGREEN = (pGREEN>255)?255:pGREEN; 171 | rBLUE = (pBLUE>255)?255:pBLUE; 172 | 173 | //save result 174 | resultImg.setPixel(x, y, 255, rRED, rGREEN, rBLUE); 175 | } 176 | } 177 | } 178 | 179 | /** 180 | * This method will multiply the pixels of the color image. 181 | * It takes a color images and adds its pixel with a constant value C. 182 | * The result of multiplication is saved in resultImg which is of the size of sourceImage. 183 | * 184 | * @param sourceImg1 The first image. 185 | * @param C The constant value to add. [0-255] 186 | * @param resultImg This will hold the resultant image after multiplication of image1 and image2. 187 | */ 188 | public static void colorImage(MyImage sourceImg1, int C, MyImage resultImg){ 189 | 190 | //image dimension - common for all the three images 191 | int width = sourceImg1.getImageWidth(); 192 | int height = sourceImg1.getImageHeight(); 193 | 194 | //variable 195 | int pRED, pGREEN, pBLUE, rRED, rGREEN, rBLUE; 196 | 197 | /** 198 | * multiply pixels 199 | */ 200 | for(int y = 0; y < height; y++){ 201 | for(int x = 0; x < width; x++){ 202 | //multiply the RGB components of the two source image 203 | pRED = sourceImg1.getRed(x, y) * C; 204 | pGREEN = sourceImg1.getGreen(x, y) * C; 205 | pBLUE = sourceImg1.getBlue(x, y) * C; 206 | 207 | //find result 208 | rRED = (pRED>255)?255:pRED; 209 | rGREEN = (pGREEN>255)?255:pGREEN; 210 | rBLUE = (pBLUE>255)?255:pBLUE; 211 | 212 | //save result 213 | resultImg.setPixel(x, y, 255, rRED, rGREEN, rBLUE); 214 | } 215 | } 216 | } 217 | }//class ends here 218 | -------------------------------------------------------------------------------- /src/imageFX/math/Subtract.java: -------------------------------------------------------------------------------- 1 | package imageFX.math; 2 | import imageFX.MyImage; 3 | 4 | /** 5 | * File: Subtract.java 6 | * 7 | * Description: 8 | * To perform subtraction of image pixels. 9 | * 10 | * @author Yusuf Shakeel 11 | * @version 1.0 12 | * Date: 25-04-2014 fri 13 | * 14 | * www.github.com/yusufshakeel/Java-Image-Processing-Project 15 | * 16 | * The MIT License (MIT) 17 | * Copyright (c) 2014 Yusuf Shakeel 18 | * 19 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 20 | * this software and associated documentation files (the "Software"), to deal in 21 | * the Software without restriction, including without limitation the rights to 22 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 23 | * the Software, and to permit persons to whom the Software is furnished to do so, 24 | * subject to the following conditions 25 | * 26 | * The above copyright notice and this permission notice shall be included in all 27 | * copies or substantial portions of the Software. 28 | * 29 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 30 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 31 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 32 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 33 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 34 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 35 | */ 36 | public class Subtract { 37 | 38 | /////////////////////////////// BINARY IMAGE //////////////////////////////// 39 | 40 | /** 41 | * This method will subtract the pixels of the binary image. 42 | * It takes two equal size binary images and subtract their pixels. 43 | * The result of subtraction is saved in resultImg which is also of the same size. 44 | * 45 | * @param sourceImg1 The first image. 46 | * @param sourceImg2 The second image. 47 | * @param resultImg This will hold the resultant image after subtraction of image1 and image2. 48 | */ 49 | public static void binaryImage(MyImage sourceImg1, MyImage sourceImg2, MyImage resultImg){ 50 | /** 51 | * Note grayscale and binary image pixel subtraction is almost same. 52 | * So, calling grayscaleImage() method 53 | */ 54 | grayscaleImage(sourceImg1, sourceImg2, resultImg); 55 | } 56 | 57 | /** 58 | * This method will subtract the pixels of the binary image. 59 | * It takes a binary images and subtracts its pixel with a constant value C. 60 | * The result of subtraction is saved in resultImg which is of same size as sourceImage. 61 | * 62 | * @param sourceImg1 The first image. 63 | * @param C The constant to add. [0-255] 64 | * @param resultImg This will hold the resultant image after subtraction of image1 and image2. 65 | */ 66 | public static void binaryImage(MyImage sourceImg1, int C, MyImage resultImg){ 67 | /** 68 | * Note grayscale and binary image pixel subtraction is almost same. 69 | * So, calling grayscaleImage() method 70 | */ 71 | grayscaleImage(sourceImg1, C, resultImg); 72 | } 73 | 74 | /////////////////////////////// GRAYSCALE IMAGE //////////////////////////// 75 | 76 | /** 77 | * This method will subtract the pixels of the grayscale image. 78 | * It takes two equal size grayscale images and subtracts their pixels. 79 | * The result of subtraction is saved in resultImg which is also of the same size. 80 | * 81 | * @param sourceImg1 The first image. 82 | * @param sourceImg2 The second image. 83 | * @param resultImg This will hold the resultant image after subtraction of image1 and image2. 84 | */ 85 | public static void grayscaleImage(MyImage sourceImg1, MyImage sourceImg2, MyImage resultImg){ 86 | 87 | //image dimension - common for all the three images 88 | int width = sourceImg1.getImageWidth(); 89 | int height = sourceImg1.getImageHeight(); 90 | 91 | //variable 92 | int p, result; 93 | 94 | /** 95 | * subtract pixels 96 | * Grayscale image will have same value for RGB so take any one component. 97 | */ 98 | for(int y = 0; y < height; y++){ 99 | for(int x = 0; x < width; x++){ 100 | p = Math.abs(sourceImg1.getBlue(x, y) - sourceImg2.getBlue(x, y)); 101 | result = (p<0)?0:p; 102 | resultImg.setPixel(x, y, 255, result, result, result); 103 | } 104 | } 105 | } 106 | 107 | /** 108 | * This method will subtract the pixels of the grayscale image. 109 | * It takes a grayscale images and subtracts its pixel with a constant value C. 110 | * The result of subtraction is saved in resultImg which is of the size of sourceImage. 111 | * 112 | * @param sourceImg1 The first image. 113 | * @param C constant number to add. [0-255] 114 | * @param resultImg This will hold the resultant image after subtraction of image1 and image2. 115 | */ 116 | public static void grayscaleImage(MyImage sourceImg1, int C, MyImage resultImg){ 117 | 118 | //image dimension - common for the two images 119 | int width = sourceImg1.getImageWidth(); 120 | int height = sourceImg1.getImageHeight(); 121 | 122 | //variable 123 | int p, result; 124 | 125 | /** 126 | * subtract pixels 127 | * Grayscale image will have same value for RGB so take any one component. 128 | */ 129 | for(int y = 0; y < height; y++){ 130 | for(int x = 0; x < width; x++){ 131 | p = Math.abs(sourceImg1.getBlue(x, y) - C); 132 | result = (p<0)?0:p; 133 | resultImg.setPixel(x, y, 255, result, result, result); 134 | } 135 | } 136 | } 137 | 138 | /////////////////////////////// COLOR IMAGE //////////////////////////////// 139 | 140 | /** 141 | * This method will subtract the pixels of the color image. 142 | * It takes two equal size color images and subtracts their pixels. 143 | * The result of subtraction is saved in resultImg which is also of the same size. 144 | * 145 | * @param sourceImg1 The first image. 146 | * @param sourceImg2 The second image. 147 | * @param resultImg This will hold the resultant image after subtraction of image1 and image2. 148 | */ 149 | public static void colorImage(MyImage sourceImg1, MyImage sourceImg2, MyImage resultImg){ 150 | 151 | //image dimension - common for all the three images 152 | int width = sourceImg1.getImageWidth(); 153 | int height = sourceImg1.getImageHeight(); 154 | 155 | //variable 156 | int pRED, pGREEN, pBLUE, rRED, rGREEN, rBLUE; 157 | 158 | /** 159 | * subtract pixels 160 | */ 161 | for(int y = 0; y < height; y++){ 162 | for(int x = 0; x < width; x++){ 163 | //subtract the RGB components of the two source image 164 | pRED = Math.abs(sourceImg1.getRed(x, y) - sourceImg2.getRed(x, y)); 165 | pGREEN = Math.abs(sourceImg1.getGreen(x, y) - sourceImg2.getGreen(x, y)); 166 | pBLUE = Math.abs(sourceImg1.getBlue(x, y) - sourceImg2.getBlue(x, y)); 167 | 168 | //find result 169 | rRED = (pRED<0)?0:pRED; 170 | rGREEN = (pGREEN<0)?0:pGREEN; 171 | rBLUE = (pBLUE<0)?0:pBLUE; 172 | 173 | //save result 174 | resultImg.setPixel(x, y, 255, rRED, rGREEN, rBLUE); 175 | } 176 | } 177 | } 178 | 179 | /** 180 | * This method will subtract the pixels of the color image. 181 | * It takes a color images and subtracts its pixel with a constant value C. 182 | * The result of subtraction is saved in resultImg which is of the size of sourceImage. 183 | * 184 | * @param sourceImg1 The first image. 185 | * @param C The constant value to add. [0-255] 186 | * @param resultImg This will hold the resultant image after subtraction of image1 and image2. 187 | */ 188 | public static void colorImage(MyImage sourceImg1, int C, MyImage resultImg){ 189 | 190 | //image dimension - common for all the three images 191 | int width = sourceImg1.getImageWidth(); 192 | int height = sourceImg1.getImageHeight(); 193 | 194 | //variable 195 | int pRED, pGREEN, pBLUE, rRED, rGREEN, rBLUE; 196 | 197 | /** 198 | * subtract pixels 199 | */ 200 | for(int y = 0; y < height; y++){ 201 | for(int x = 0; x < width; x++){ 202 | //subtract the RGB components of the two source image 203 | pRED = Math.abs(sourceImg1.getRed(x, y) - C); 204 | pGREEN = Math.abs(sourceImg1.getGreen(x, y) - C); 205 | pBLUE = Math.abs(sourceImg1.getBlue(x, y) - C); 206 | 207 | //find result 208 | rRED = (pRED<0)?0:pRED; 209 | rGREEN = (pGREEN<0)?0:pGREEN; 210 | rBLUE = (pBLUE<0)?0:pBLUE; 211 | 212 | //save result 213 | resultImg.setPixel(x, y, 255, rRED, rGREEN, rBLUE); 214 | } 215 | } 216 | } 217 | }//class ends here 218 | -------------------------------------------------------------------------------- /src/imageFX/morph/Closing.java: -------------------------------------------------------------------------------- 1 | package imageFX.morph; 2 | import imageFX.MyImage; 3 | 4 | /** 5 | * File: Closing.java 6 | * 7 | * Description: 8 | * Implements the image morphology operation: closing. 9 | * 10 | * CLosing is defined as dilation followed by erosion of image. 11 | * 12 | * WHITE is represented as (255,255,255,255) and BLACK as (255,0,0,0) in ARGB form respectively. 13 | * 14 | * @author Yusuf Shakeel 15 | * @version 1.0 16 | * date: 24-04-2014 Thu 17 | * 18 | * www.github.com/yusufshakeel/Java-Image-Processing-Project 19 | * 20 | * The MIT License (MIT) 21 | * Copyright (c) 2014 Yusuf Shakeel 22 | * 23 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 24 | * this software and associated documentation files (the "Software"), to deal in 25 | * the Software without restriction, including without limitation the rights to 26 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 27 | * the Software, and to permit persons to whom the Software is furnished to do so, 28 | * subject to the following conditions 29 | * 30 | * The above copyright notice and this permission notice shall be included in all 31 | * copies or substantial portions of the Software. 32 | * 33 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 34 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 35 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 36 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 37 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 38 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 39 | */ 40 | public class Closing { 41 | 42 | /** 43 | * This method will perform closing on binary image img. 44 | * 45 | * @param img The image on which opening is performed. 46 | */ 47 | public static void binaryImage(MyImage img){ 48 | Dilation.binaryImage(img, true); 49 | Erosion.binaryImage(img, true); 50 | } 51 | 52 | /** 53 | * This method will perform closing on grayscale image img. 54 | * 55 | * @param img The image on which opening is performed. 56 | * @param mask The square mask 57 | * @param maskSize The size of the square mask [No. of rows or columns of the square mask] 58 | */ 59 | public static void grayscaleImage(MyImage img, int mask[], int maskSize){ 60 | Dilation.grayscaleImage(img, mask, maskSize); 61 | Erosion.grayscaleImage(img, mask, maskSize); 62 | } 63 | }//class ends here 64 | -------------------------------------------------------------------------------- /src/imageFX/morph/HitMiss.java: -------------------------------------------------------------------------------- 1 | package imageFX.morph; 2 | import imageFX.MyImage; 3 | 4 | /** 5 | * File: HitMiss.java 6 | * 7 | * Description: 8 | * Implements the image morphology operation: hit-miss 9 | * 10 | * @author Yusuf Shakeel 11 | * @version 1.0 12 | * date: 29-04-2014 tue 13 | * 14 | * www.github.com/yusufshakeel/Java-Image-Processing-Project 15 | * 16 | * The MIT License (MIT) 17 | * Copyright (c) 2014 Yusuf Shakeel 18 | * 19 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 20 | * this software and associated documentation files (the "Software"), to deal in 21 | * the Software without restriction, including without limitation the rights to 22 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 23 | * the Software, and to permit persons to whom the Software is furnished to do so, 24 | * subject to the following conditions 25 | * 26 | * The above copyright notice and this permission notice shall be included in all 27 | * copies or substantial portions of the Software. 28 | * 29 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 30 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 31 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 32 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 33 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 34 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 35 | */ 36 | public class HitMiss { 37 | 38 | ///////////////////////// BINARY IMAGE ///////////////////////////////////// 39 | 40 | /** 41 | * This method will perform hit-miss operation on the binary image img. 42 | * A binary image has two types of pixels - Black and White. 43 | * WHITE pixel has the ARGB value (255,255,255,255) 44 | * BLACK pixel has the ARGB value (255,0,0,0) 45 | * 46 | * The 2D mask array has three types of values. 47 | * 0 for BLACK i.e., BACKGROUND 48 | * 1 for WHITE i.e., FOREGROUND 49 | * 2 for DON'T CARE 50 | * 51 | * @param img The image on which hit miss operation is performed 52 | * @param mask 2D array of square mask. 53 | * @param maskSize The size of the square mask - no. of rows. 54 | */ 55 | public static void binaryImage(MyImage img,int mask[], int maskSize){ 56 | /** 57 | * Dimension of the image img. 58 | */ 59 | int width = img.getImageWidth(); 60 | int height = img.getImageHeight(); 61 | 62 | /** 63 | * This will hold the dilation result which will be copied to image img. 64 | */ 65 | int output[] = new int[width * height]; 66 | 67 | //perform hit-miss 68 | for(int y = 0; y < height; y++){ 69 | for(int x = 0; x < width; x++){ 70 | boolean flag = false; //this will be set if mismatch is found 71 | for(int ty = y - (maskSize/2), mr = 0; ty <= y + (maskSize/2) && flag == false; ty++, mr++){ 72 | for(int tx = x - (maskSize/2), mc = 0; tx <= x + (maskSize/2) && flag == false; tx++, mc++){ 73 | //pixel under the mask 74 | if(ty >= 0 && ty < height && tx >= 0 && tx < width){ 75 | 76 | //for don't-care value in mask 77 | if(mask[mc+mr*maskSize] > 1){ 78 | continue; 79 | } 80 | 81 | //if image pixel not same as mask 82 | if(img.getRed(tx, ty) != (mask[mc+mr*maskSize]*255)){ 83 | flag = true; 84 | output[x+y*width] = 0; //BLACK 85 | break; 86 | } 87 | } 88 | } 89 | } 90 | if(flag == false){ 91 | //all pixels of image under the mask has matched 92 | output[x+y*width] = 255; //FOREGROUND COLOR WHITE 93 | } 94 | } 95 | } 96 | 97 | /** 98 | * Save the hit miss value in image img. 99 | */ 100 | for(int y = 0; y < height; y++){ 101 | for(int x = 0; x < width; x++){ 102 | int v = output[x+y*width]; 103 | img.setPixel(x, y, 255, v, v, v); 104 | } 105 | } 106 | } 107 | }//class ends here 108 | -------------------------------------------------------------------------------- /src/imageFX/morph/Opening.java: -------------------------------------------------------------------------------- 1 | package imageFX.morph; 2 | import imageFX.MyImage; 3 | 4 | /** 5 | * File: Opening.java 6 | * 7 | * Description: 8 | * Implements the image morphology operation: opening. 9 | * 10 | * Opening is defined as an erosion followed by a dilation. 11 | * 12 | * WHITE is represented as (255,255,255,255) and BLACK as (255,0,0,0) in ARGB form respectively. 13 | * 14 | * @author Yusuf Shakeel 15 | * @version 1.0 16 | * date: 24-04-2014 Thu 17 | * 18 | * www.github.com/yusufshakeel/Java-Image-Processing-Project 19 | * 20 | * The MIT License (MIT) 21 | * Copyright (c) 2014 Yusuf Shakeel 22 | * 23 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 24 | * this software and associated documentation files (the "Software"), to deal in 25 | * the Software without restriction, including without limitation the rights to 26 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 27 | * the Software, and to permit persons to whom the Software is furnished to do so, 28 | * subject to the following conditions 29 | * 30 | * The above copyright notice and this permission notice shall be included in all 31 | * copies or substantial portions of the Software. 32 | * 33 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 34 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 35 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 36 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 37 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 38 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 39 | */ 40 | public class Opening { 41 | 42 | /** 43 | * This method will perform opening on image img. 44 | * 45 | * For erosion we generally consider foreground pixel. So, erodeBlackpixel = false 46 | * For dilation we generally consider the background pixel. So, dilateBlackPixel = true. 47 | * 48 | * @param img The image on which opening is performed. 49 | * @param erodeBlackPixel If set to TRUE will perform erosion on BLACK pixels else on WHITE pixels. 50 | * @param dilateBlackPixel If set to TRUE will perform dilation on BLACK pixels else on WHITE pixels. 51 | */ 52 | public static void binaryImage(MyImage img, boolean erodeBlackPixel, boolean dilateBlackPixel){ 53 | Erosion.binaryImage(img, erodeBlackPixel); 54 | Dilation.binaryImage(img, dilateBlackPixel); 55 | } 56 | }//class ends here 57 | -------------------------------------------------------------------------------- /src/imageFX/morph/Skeletonization.java: -------------------------------------------------------------------------------- 1 | package imageFX.morph; 2 | import imageFX.MyImage; 3 | import imageFX.morph.Thinning; 4 | 5 | /** 6 | * File: Skeletonization.java 7 | * 8 | * Description: 9 | * This will create a thin the image. 10 | * It uses Thinning morphological concept. 11 | * 12 | * @author Yusuf Shakeel 13 | * @version 1.0 14 | * date: 29-04-2014 tue 15 | * 16 | * www.github.com/yusufshakeel/Java-Image-Processing-Project 17 | * 18 | * The MIT License (MIT) 19 | * Copyright (c) 2014 Yusuf Shakeel 20 | * 21 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 22 | * this software and associated documentation files (the "Software"), to deal in 23 | * the Software without restriction, including without limitation the rights to 24 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 25 | * the Software, and to permit persons to whom the Software is furnished to do so, 26 | * subject to the following conditions 27 | * 28 | * The above copyright notice and this permission notice shall be included in all 29 | * copies or substantial portions of the Software. 30 | * 31 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 32 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 33 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 34 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 35 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 36 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 37 | */ 38 | public class Skeletonization { 39 | 40 | /** 41 | * This method will perform skeletonization [thinning] operation on the binary image img. 42 | * 43 | * @param img The image to thin. 44 | */ 45 | public static void binaryImage(MyImage img){ 46 | 47 | //1st set of masks 48 | int mask1[] = new int[]{ 49 | 0,0,0, 50 | 2,1,2, 51 | 1,1,1 52 | }; 53 | int mask2[] = new int[]{ 54 | 0,2,1, 55 | 0,1,1, 56 | 0,2,1 57 | }; 58 | int mask3[] = new int[]{ 59 | 1,1,1, 60 | 2,1,2, 61 | 0,0,0 62 | }; 63 | int mask4[] = new int[]{ 64 | 1,2,0, 65 | 1,1,0, 66 | 1,2,0 67 | }; 68 | 69 | //2nd set of masks 70 | int mask5[] = new int[]{ 71 | 2,0,0, 72 | 1,1,0, 73 | 2,1,2 74 | }; 75 | int mask6[] = new int[]{ 76 | 0,0,2, 77 | 0,1,1, 78 | 2,1,2 79 | }; 80 | int mask7[] = new int[]{ 81 | 2,1,2, 82 | 0,1,1, 83 | 0,0,2 84 | }; 85 | int mask8[] = new int[]{ 86 | 2,1,2, 87 | 1,1,0, 88 | 2,0,0 89 | }; 90 | 91 | //thin image till no change occurs 92 | MyImage tmpImg; 93 | int count = 0; 94 | do{ 95 | tmpImg = new MyImage(img); 96 | 97 | //thin with mask1 98 | Thinning.binaryImage(img, mask1, 3); 99 | 100 | //thin with mask5 101 | Thinning.binaryImage(img, mask5, 3); 102 | 103 | //thin with rest of the masks 104 | Thinning.binaryImage(img, mask2, 3); 105 | Thinning.binaryImage(img, mask3, 3); 106 | Thinning.binaryImage(img, mask4, 3); 107 | Thinning.binaryImage(img, mask6, 3); 108 | Thinning.binaryImage(img, mask7, 3); 109 | Thinning.binaryImage(img, mask8, 3); 110 | 111 | count++; 112 | System.out.println("Skeletonization() Loop Executed: "+count+" times."); 113 | }while(img.isEqual(tmpImg) == false); //change occured, so continue with the loop 114 | } 115 | }//class ends here 116 | -------------------------------------------------------------------------------- /src/imageFX/morph/Thinning.java: -------------------------------------------------------------------------------- 1 | package imageFX.morph; 2 | import imageFX.MyImage; 3 | import imageFX.math.Subtract; 4 | 5 | /** 6 | * File: Thinning.java 7 | * 8 | * Description: 9 | * Implements the image morphology operation: thinning 10 | * 11 | * @author Yusuf Shakeel 12 | * @version 1.0 13 | * date: 29-04-2014 tue 14 | * 15 | * www.github.com/yusufshakeel/Java-Image-Processing-Project 16 | * 17 | * The MIT License (MIT) 18 | * Copyright (c) 2014 Yusuf Shakeel 19 | * 20 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 21 | * this software and associated documentation files (the "Software"), to deal in 22 | * the Software without restriction, including without limitation the rights to 23 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 24 | * the Software, and to permit persons to whom the Software is furnished to do so, 25 | * subject to the following conditions 26 | * 27 | * The above copyright notice and this permission notice shall be included in all 28 | * copies or substantial portions of the Software. 29 | * 30 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 31 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 32 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 33 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 34 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 35 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 36 | */ 37 | public class Thinning { 38 | 39 | /** 40 | * This method will perform thinning operation on the binary image. 41 | * 42 | * @param img The binary image on which thinning is performed. 43 | * @param mask The mask used for thinning. [Mask is a 2D matrix stored in 1D array] 44 | * @param maskSize The size of the mask. [No. of rows in the 2D mask matrix] 45 | */ 46 | public static void binaryImage(MyImage img, int mask[], int maskSize){ 47 | /** 48 | * How it works: 49 | * If we consider an image I and a mask M, then thinning T can be expressed as: 50 | * T(I,M) = I - HitMiss(I,M) 51 | */ 52 | MyImage tmp = new MyImage(img); 53 | HitMiss.binaryImage(tmp, mask, maskSize); 54 | Subtract.binaryImage(img, tmp, img); 55 | } 56 | }//class ends here 57 | -------------------------------------------------------------------------------- /src/mypackage/ImageProject.java: -------------------------------------------------------------------------------- 1 | package mypackage; 2 | /** 3 | * File: ImageProject.java 4 | * 5 | * Description: 6 | * This is a test file. 7 | * 8 | * @author Yusuf Shakeel 9 | * @version 1.0 10 | * Date: 26-01-2014 sun 11 | */ 12 | 13 | import imageFX.*; 14 | 15 | public class ImageProject { 16 | 17 | /** 18 | * @param args the command line arguments 19 | */ 20 | public static void main(String[] args){ 21 | test(); 22 | }//main() ends here 23 | 24 | public static void test(){ 25 | MyImage iobj = new MyImage(3000,1500); 26 | DYMosaic.myColorMosaic(iobj, DYColor.Ruby_red, 100); 27 | iobj.writeImage("D:\\Mosaic-3000x1500.png"); 28 | } 29 | }//class ImageProject ends here -------------------------------------------------------------------------------- /test-image/test1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yusufshakeel/Java-Image-Processing-Project/da1ff27b3c69dc5d17a1570bb712c0217f712448/test-image/test1.png -------------------------------------------------------------------------------- /test-image/test2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yusufshakeel/Java-Image-Processing-Project/da1ff27b3c69dc5d17a1570bb712c0217f712448/test-image/test2.png -------------------------------------------------------------------------------- /test-image/test3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yusufshakeel/Java-Image-Processing-Project/da1ff27b3c69dc5d17a1570bb712c0217f712448/test-image/test3.png -------------------------------------------------------------------------------- /test-image/test4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yusufshakeel/Java-Image-Processing-Project/da1ff27b3c69dc5d17a1570bb712c0217f712448/test-image/test4.png -------------------------------------------------------------------------------- /test-image/test5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yusufshakeel/Java-Image-Processing-Project/da1ff27b3c69dc5d17a1570bb712c0217f712448/test-image/test5.png -------------------------------------------------------------------------------- /test-image/test6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yusufshakeel/Java-Image-Processing-Project/da1ff27b3c69dc5d17a1570bb712c0217f712448/test-image/test6.png -------------------------------------------------------------------------------- /test-image/test7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yusufshakeel/Java-Image-Processing-Project/da1ff27b3c69dc5d17a1570bb712c0217f712448/test-image/test7.png -------------------------------------------------------------------------------- /test-image/test8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yusufshakeel/Java-Image-Processing-Project/da1ff27b3c69dc5d17a1570bb712c0217f712448/test-image/test8.png --------------------------------------------------------------------------------