removed unnessary imports and main in ImageProcessing and started besoin 8
This commit is contained in:
1 parent
b949a317c3
commit
dbaf3401b8
2 files changed
+56
-50
No files matched your search
@@ -6,12 +6,17 @@ import java.io.InputStream;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import javax.imageio.ImageIO;
|
||||||
import javax.print.attribute.standard.Media;
|
import javax.print.attribute.standard.Media;
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.fasterxml.jackson.databind.node.ArrayNode;
|
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||||
|
|
||||||
|
import boofcv.io.image.ConvertBufferedImage;
|
||||||
|
import boofcv.struct.image.GrayU8;
|
||||||
|
import boofcv.struct.image.Planar;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.core.io.InputStreamResource;
|
import org.springframework.core.io.InputStreamResource;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
@@ -27,6 +32,9 @@ import org.springframework.web.bind.annotation.RestController;
|
|||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
|
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
|
||||||
|
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
|
import java.awt.image.DataBufferInt;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
public class ImageController {
|
public class ImageController {
|
||||||
|
|
||||||
@@ -39,18 +47,6 @@ public class ImageController {
|
|||||||
this.imageDao = imageDao;
|
this.imageDao = imageDao;
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping(value = "/images/{id}", produces = MediaType.IMAGE_JPEG_VALUE || MediaType.IMAGE_PNG_VALUE)
|
|
||||||
public ResponseEntity<?> getImage(@PathVariable("id") long id) {
|
|
||||||
|
|
||||||
Optional<Image> image = imageDao.retrieve(id);
|
|
||||||
|
|
||||||
if (image.isPresent()) {
|
|
||||||
InputStream inputStream = new ByteArrayInputStream(image.get().getData());
|
|
||||||
return ResponseEntity.ok().contentType(image.getMediaType()).body(new InputStreamResource(inputStream));
|
|
||||||
}
|
|
||||||
return new ResponseEntity<>("Image id=" + id + " not found.", HttpStatus.NOT_FOUND);
|
|
||||||
}
|
|
||||||
|
|
||||||
@DeleteMapping(value = "/images/{id}")
|
@DeleteMapping(value = "/images/{id}")
|
||||||
public ResponseEntity<?> deleteImage(@PathVariable("id") long id) {
|
public ResponseEntity<?> deleteImage(@PathVariable("id") long id) {
|
||||||
|
|
||||||
@@ -67,7 +63,8 @@ public class ImageController {
|
|||||||
public ResponseEntity<?> addImage(@RequestParam("file") MultipartFile file, RedirectAttributes redirectAttributes) {
|
public ResponseEntity<?> addImage(@RequestParam("file") MultipartFile file, RedirectAttributes redirectAttributes) {
|
||||||
|
|
||||||
String contentType = file.getContentType();
|
String contentType = file.getContentType();
|
||||||
if (contentType != null && !contentType.equals(MediaType.IMAGE_JPEG.toString()) && !contentType.equals(MediaType.IMAGE_PNG.toString())) {
|
if (contentType != null && !contentType.equals(MediaType.IMAGE_JPEG.toString())
|
||||||
|
&& !contentType.equals(MediaType.IMAGE_PNG.toString())) {
|
||||||
return new ResponseEntity<>("Only JPEG/PNG file format supported", HttpStatus.UNSUPPORTED_MEDIA_TYPE);
|
return new ResponseEntity<>("Only JPEG/PNG file format supported", HttpStatus.UNSUPPORTED_MEDIA_TYPE);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
@@ -94,18 +91,54 @@ public class ImageController {
|
|||||||
return nodes;
|
return nodes;
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping(value = "/images/{id}?algorithm={X}&p1={Y}&p2={Z}", produces = MediaType.IMAGE_JPEG_VALUE || MediaType.IMAGE_PNG_VALUE)
|
@GetMapping(value = "/images/{id}", produces = { MediaType.IMAGE_JPEG_VALUE,
|
||||||
public ResponseEntity<?> applyAlgorithm(@PathVariable("id") long id, @PathVariable("X") string algorithm, @PathVariable("Y") int firstParam, @PathVariable("Z") int secondParam) {
|
MediaType.IMAGE_PNG_VALUE })
|
||||||
|
public ResponseEntity<?> applyAlgorithm(@PathVariable("id") long id,
|
||||||
|
@RequestParam(required = false) String algorithm,
|
||||||
|
@RequestParam(required = false) Long p1, @RequestParam(required = false) Long p2) {
|
||||||
|
|
||||||
Optional<Image> image = imageDao.retrieve(id);
|
Optional<Image> image = imageDao.retrieve(id);
|
||||||
if (image.isPresent()) {
|
if (image.isPresent()) {
|
||||||
if (algorithm.equals("changeLuminosity")){
|
if (algorithm == null) {
|
||||||
Optional<Image> changedImage = createSameShape(image);
|
InputStream inputStream = new ByteArrayInputStream(image.get().getData());
|
||||||
ImageProcessing.changeLuminosity(changedImage, firstParam);
|
return ResponseEntity.ok().contentType(image.get().getMediaType())
|
||||||
|
.body(new InputStreamResource(inputStream));
|
||||||
|
|
||||||
}
|
}
|
||||||
InputStream inputStream = new ByteArrayInputStream(changedImage.get().getData());
|
if (algorithm.equals("changeLuminosity")) {
|
||||||
return ResponseEntity.ok().contentType(MediaType.IMAGE_JPEG).body(new InputStreamResource(inputStream));
|
BufferedImage bufImg;
|
||||||
|
try {
|
||||||
|
bufImg = ImageIO.read(new ByteArrayInputStream(image.get().getData()));
|
||||||
|
} catch (IOException e) {
|
||||||
|
return new ResponseEntity<>("Image not readable",
|
||||||
|
HttpStatus.INTERNAL_SERVER_ERROR);
|
||||||
}
|
}
|
||||||
return new ResponseEntity<>("Image id=" + id + " not found.", HttpStatus.NOT_FOUND);
|
Planar<GrayU8> input = ConvertBufferedImage.convertFromPlanar(bufImg, null,
|
||||||
|
true, GrayU8.class);
|
||||||
|
ImageProcessing.changeLuminosity(input, (int) p1.longValue());
|
||||||
|
|
||||||
|
int width = input.getWidth();
|
||||||
|
int height = input.getHeight();
|
||||||
|
int numChannels = input.getNumBands();
|
||||||
|
|
||||||
|
// Allocate a byte array to hold the pixel data
|
||||||
|
byte[] imageData = new byte[width * height * numChannels];
|
||||||
|
|
||||||
|
// Iterate over the planes and copy the pixel data into the byte array
|
||||||
|
for (int i = 0; i < numChannels; i++) {
|
||||||
|
byte[] planeData = input.getBand(i).getData();
|
||||||
|
System.arraycopy(planeData, 0, imageData, i * width * height, width *
|
||||||
|
height);
|
||||||
|
}
|
||||||
|
|
||||||
|
InputStream inputStream = new ByteArrayInputStream(image.get().getData());
|
||||||
|
// InputStream inputStream = new ByteArrayInputStream(imageData);
|
||||||
|
System.out.println("hi");
|
||||||
|
return ResponseEntity.ok().contentType(image.get().getMediaType())
|
||||||
|
.body(new InputStreamResource(inputStream));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new ResponseEntity<>("Image id=" + id + " not found.",
|
||||||
|
HttpStatus.NOT_FOUND);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,10 +1,6 @@
|
|||||||
package pdl.backend;
|
package pdl.backend;
|
||||||
|
|
||||||
import java.awt.image.BufferedImage;
|
|
||||||
import boofcv.io.image.UtilImageIO;
|
|
||||||
import boofcv.io.image.ConvertBufferedImage;
|
|
||||||
import boofcv.struct.image.GrayU8;
|
import boofcv.struct.image.GrayU8;
|
||||||
import boofcv.struct.border.BorderType;
|
|
||||||
import boofcv.struct.image.Planar;
|
import boofcv.struct.image.Planar;
|
||||||
|
|
||||||
public class ImageProcessing {
|
public class ImageProcessing {
|
||||||
@@ -127,7 +123,6 @@ public class ImageProcessing {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Passe un pixel de l'espace de couleurs RGB à l'espace de couleurs HSV :
|
* Passe un pixel de l'espace de couleurs RGB à l'espace de couleurs HSV :
|
||||||
@@ -249,7 +244,7 @@ public class ImageProcessing {
|
|||||||
for (int x = 0; x < input.width; x++) {
|
for (int x = 0; x < input.width; x++) {
|
||||||
if (y < half || x < half || y >= input.height - half || x >= input.width - half) {
|
if (y < half || x < half || y >= input.height - half || x >= input.width - half) {
|
||||||
int gl = inputGray.getBand(0).get(x, y);
|
int gl = inputGray.getBand(0).get(x, y);
|
||||||
int[] rgb = {gl,gl,gl};
|
int[] rgb = { gl, gl, gl };
|
||||||
setRGBValue(output, x, y, rgb);
|
setRGBValue(output, x, y, rgb);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -271,15 +266,12 @@ public class ImageProcessing {
|
|||||||
value = 0;
|
value = 0;
|
||||||
if (value > 255)
|
if (value > 255)
|
||||||
value = 255;
|
value = 255;
|
||||||
int[] rgb = {value, value, value};
|
int[] rgb = { value, value, value };
|
||||||
setRGBValue(output, x, y, rgb);
|
setRGBValue(output, x, y, rgb);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Applique un filtre moyenneur de taille indiquée à l'image
|
* Applique un filtre moyenneur de taille indiquée à l'image
|
||||||
* passée en paramètre (le bord de l'image n'est pas modifié)
|
* passée en paramètre (le bord de l'image n'est pas modifié)
|
||||||
@@ -372,23 +364,4 @@ public class ImageProcessing {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
if (args.length < 2) {
|
|
||||||
System.out.println("missing input or output image filename");
|
|
||||||
System.exit(-1);
|
|
||||||
}
|
|
||||||
final String inputPath = args[0];
|
|
||||||
BufferedImage image = UtilImageIO.loadImage(inputPath);
|
|
||||||
Planar<GrayU8> input = ConvertBufferedImage.convertFromPlanar(image, null, true, GrayU8.class);
|
|
||||||
Planar<GrayU8> output = input.createSameShape();
|
|
||||||
long beginning = System.nanoTime();
|
|
||||||
histogram(input);
|
|
||||||
long end = System.nanoTime();
|
|
||||||
System.out.println("Duration : " + ((end - beginning) / 1000000) + "ms");
|
|
||||||
// save output image
|
|
||||||
final String outputPath = args[1];
|
|
||||||
UtilImageIO.saveImage(input, outputPath);
|
|
||||||
System.out.println("Image saved in: " + outputPath); }
|
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user