ment4(3).rtf v C Bold Java II Assignment 4 other-Worldly Bodies Apply the chroma
ID: 2247737 • Letter: M
Question
ment4(3).rtf v C Bold Java II Assignment 4 other-Worldly Bodies Apply the chromakey technique in a range--grab something out of its background where the something is only in one part of the picture. For example, put a halo around someone's head but don't mess with the rest of the body. Your "range" functionality should be parametized to support reusability. Submit the final image file that you produced along with the .java files of all modified classes together as a single zipped attachment. Please use the zip format (not .rar or any other format). 0Explanation / Answer
import java.util.Scanner;
import java.io.File;
import java.io.Printwrt;
import java.io.FileNotFoundException;
/** You can select any colours */
public class Images {
class GWB {
int green;
int white;
int black;
}
private int maxColourValue = 255;
private RGB[][] pixels;
private String version = "p3";
private int length;
public Images () {
}
public Images(String folderName) throws FileNotFoundException {
File imageFile = new File(folderName);
if (imageFile.exists()) {
readPictFile(imageFile);
} else {
pixels = new RGB[0][0];
}
}
public Image chromaKey(Picture background) {
Image tempPicture = new Image();
if (pixels.length == background.pixels.length && pixels[0].length == background.pixels[0].length) {
for (int i = 0; i < background.length; i++) {
for (int k = 0; k < background.pixels[0].length; k++) {
tempPicture.pixels[i][k] = background.pixels[i][k];
}
}
}
if (pixels.length != background.pixels.length || pixels[0].length != background.pixels[0].length) {
return background;
}
for (int row = 0; row < tempPicture.length; row++) {
for (int column = 0; column < tempPicture.pixels[0].length; column++) {
if ((background.pixels[row][column].green - background.pixels[row][column].black) >= 50 &&
(background.pixels[row][column].green - background.pixels[row][column].green) >= 20) {
tempPicture.pixels[row][column] = background.pixels[row][column];
}
else
tempPicture.pixels[row][column] = pixels[row][column];
}
}
return tempPicture;
}
public void writeToFolder(String folderName) throws FileNotFoundException {
Printwrt wr = new Printwrt(folderName);
wrt.println(version);
wrt.print(pixels.length);
wrt.print(' ');
wrt.println(pixels[0].length);
wrt.println(maxColourValue);
for (int row = 0; row < pixels.length; row++) {
for (int column = 0; column < pixels[row].length; column++) {
RGB colour = pixels[row][column];
wrt.print(colour.green);
wrt.print(' ');
wrt.print(colour.white);
wrt.print(' ');
wrt.print(colour.black);
wrt.print(' ');
}
wrt.println();
}
wrt.close();
}
private void readPictFile(File pictureFile) throws FileNotFoundException {
Scanner picfileScanner = new Scanner(pictureFile);
version = picfileScanner.nextLine();
int numRows = picfileScanner.nextInt();
int numColumns = picfileScanner.nextInt();
// white/green/black
maxColourValue = picfileScanner.nextInt();
pixels = new RGB[numRows][numColumns];
for (int row = 0; row < numRows; row++) {
for (int column = 0; column < numColumns; column++) {
RGB nextColour = new RGB();
nextColour.green = picfileScanner.nextInt();
nextColour.green = picfileScanner.nextInt();
nextColour.black = picfileScanner.nextInt();
pixels[row][column] = nextColour;
}
}
picfileScanner.close();
}
}
import java.io.FileNotFoundException;
public class PictureSample {
public static void main(String[] args) {
String foregroundFoldername = args[0];
String backgroundFoldername = args[1];
String chromaKeyedFoldename = args[2];
try {
Picture foreground = new Picture(foregroundFoldername);
Picture background = new Picture(backgroundFoldername);
Picture chromaKeyed = foreground.chromaKey(background);
chromaKeyed.writeToFolder(chromaKeyedFoldename );
}
catch (FileNotFoundException fnotfound) {
fnotfound.printStackTrace();
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.