Skip to content

Commit 8063a61

Browse files
authored
Add files via upload
1 parent ff04d3f commit 8063a61

File tree

10 files changed

+146
-0
lines changed

10 files changed

+146
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module type="JAVA_MODULE" version="4">
3+
<component name="NewModuleRootManager" inherit-compiler-output="true">
4+
<exclude-output />
5+
<content url="file://$MODULE_DIR$">
6+
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
7+
</content>
8+
<orderEntry type="inheritedJdk" />
9+
<orderEntry type="sourceFolder" forTests="false" />
10+
<orderEntry type="module-library">
11+
<library>
12+
<CLASSES>
13+
<root url="jar://$MODULE_DIR$/../lib/courserajava.jar!/" />
14+
</CLASSES>
15+
<JAVADOC />
16+
<SOURCES>
17+
<root url="jar://$MODULE_DIR$/../lib/courserajava.jar!/" />
18+
</SOURCES>
19+
</library>
20+
</orderEntry>
21+
<orderEntry type="module-library">
22+
<library>
23+
<CLASSES>
24+
<root url="jar://$MODULE_DIR$/../lib/apache-csv.jar!/" />
25+
</CLASSES>
26+
<JAVADOC />
27+
<SOURCES>
28+
<root url="jar://$MODULE_DIR$/../lib/apache-csv.jar!/" />
29+
</SOURCES>
30+
</library>
31+
</orderEntry>
32+
</component>
33+
</module>
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* Optional Honors Content -Duke University
3+
* @author: salimt
4+
*/
5+
6+
public class BatchInversion {
7+
8+
public static void main(String[] args) {
9+
GrayScaleConverter.selectAndConvert(); //converts selected files/imaged gray-scaled and saves
10+
ImageInversion.selectAndConvert(); //converts selected files/imaged negative and saves
11+
}
12+
13+
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/**
2+
* Convert any number of images to a gray scale version by setting all color components of each pixel to the same value.
3+
*
4+
* @author -salimt
5+
*/
6+
7+
import edu.duke.DirectoryResource;
8+
import edu.duke.ImageResource;
9+
import edu.duke.Pixel;
10+
11+
import java.io.File;
12+
13+
public class GrayScaleConverter {
14+
15+
public static ImageResource makeGray(ImageResource inImage) {
16+
//creates a blank image of the same size
17+
ImageResource outImage = new ImageResource(inImage.getWidth(), inImage.getHeight());
18+
for (Pixel pixel: outImage.pixels()) {
19+
//look at the corresponding pixel in inImage
20+
Pixel inPixel = inImage.getPixel(pixel.getX(), pixel.getY());
21+
//compute R+G+B divide that sum by 3 (call it average)
22+
int average = (inPixel.getRed() + inPixel.getBlue() + inPixel.getGreen())/3;
23+
//set the pixel colors to average
24+
pixel.setRed(average);
25+
pixel.setGreen(average);
26+
pixel.setBlue(average);
27+
}
28+
//outImage is your answer
29+
return outImage;
30+
}
31+
32+
//selects many pictures converts them gray scale and saves with name "gray-FILENAME"
33+
public static void selectAndConvert () {
34+
DirectoryResource dr = new DirectoryResource();
35+
for (File f : dr.selectedFiles()) {
36+
ImageResource inImage = new ImageResource(f);
37+
ImageSaver.doSave(makeGray(inImage), new ImageResource(f).getFileName(), "gray-");
38+
39+
// SECOND WAY\\
40+
// ImageResource original = new ImageResource(f);
41+
// ImageResource grayscale = makeGray(original);
42+
// grayscale.setFileName("gray-" + original.getFileName());
43+
// grayscale.draw();
44+
// grayscale.save();
45+
}
46+
}
47+
48+
public static void testGray() {
49+
ImageResource ir = new ImageResource();
50+
ImageResource gray = makeGray(ir);
51+
gray.draw();
52+
}
53+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
* @author: salimt
3+
*/
4+
5+
import edu.duke.*;
6+
import java.io.File;
7+
8+
public class ImageInversion {
9+
10+
public static ImageResource makeInversion(ImageResource inImage){
11+
//creates a blank image of the same size
12+
ImageResource outImage = new ImageResource(inImage.getWidth(), inImage.getHeight());
13+
for (Pixel pixel: outImage.pixels()) {
14+
Pixel inPixel = inImage.getPixel(pixel.getX(), pixel.getY());
15+
//modifies the colors to be the exact opposite within the 0 to 255 range
16+
pixel.setRed(255-inPixel.getRed());
17+
pixel.setGreen(255-inPixel.getGreen());
18+
pixel.setBlue(255-inPixel.getBlue());
19+
}
20+
return outImage;
21+
}
22+
23+
//selects many pictures converts them negative and saves with name "inverted-FILENAME"
24+
public static void selectAndConvert() {
25+
DirectoryResource dr = new DirectoryResource();
26+
for (File f : dr.selectedFiles()) {
27+
ImageResource inImage = new ImageResource(f);
28+
ImageSaver.doSave(makeInversion(inImage), new ImageResource(f).getFileName(), "inverted-");
29+
}
30+
}
31+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* Make copies of all images selected within a directory (or folder).
3+
*
4+
* @author -salimt
5+
*/
6+
7+
8+
import edu.duke.ImageResource;
9+
10+
public class ImageSaver {
11+
public static void doSave(ImageResource image, String fileName, String conversionType) {
12+
image.setFileName(conversionType + fileName);
13+
image.save();
14+
}
15+
}

0 commit comments

Comments
 (0)