removed unnessary imports and main in ImageProcessing and started besoin 8
This commit is contained in:
1 parent
b949a317c3
commit
dbaf3401b8
2 files changed
+53
-47
No files matched your search
@@ -6,12 +6,17 @@ import java.io.InputStream;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.print.attribute.standard.Media;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
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.core.io.InputStreamResource;
|
||||
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.servlet.mvc.support.RedirectAttributes;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.image.DataBufferInt;
|
||||
|
||||
@RestController
|
||||
public class ImageController {
|
||||
|
||||
@@ -39,18 +47,6 @@ public class ImageController {
|
||||
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}")
|
||||
public ResponseEntity<?> deleteImage(@PathVariable("id") long id) {
|
||||
|
||||
@@ -67,7 +63,8 @@ public class ImageController {
|
||||
public ResponseEntity<?> addImage(@RequestParam("file") MultipartFile file, RedirectAttributes redirectAttributes) {
|
||||
|
||||
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);
|
||||
}
|
||||
try {
|
||||
@@ -94,18 +91,54 @@ public class ImageController {
|
||||
return nodes;
|
||||
}
|
||||
|
||||
@GetMapping(value = "/images/{id}?algorithm={X}&p1={Y}&p2={Z}", produces = MediaType.IMAGE_JPEG_VALUE || MediaType.IMAGE_PNG_VALUE)
|
||||
public ResponseEntity<?> applyAlgorithm(@PathVariable("id") long id, @PathVariable("X") string algorithm, @PathVariable("Y") int firstParam, @PathVariable("Z") int secondParam) {
|
||||
@GetMapping(value = "/images/{id}", produces = { MediaType.IMAGE_JPEG_VALUE,
|
||||
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);
|
||||
if (image.isPresent()) {
|
||||
if (algorithm == null) {
|
||||
InputStream inputStream = new ByteArrayInputStream(image.get().getData());
|
||||
return ResponseEntity.ok().contentType(image.get().getMediaType())
|
||||
.body(new InputStreamResource(inputStream));
|
||||
|
||||
}
|
||||
if (algorithm.equals("changeLuminosity")) {
|
||||
Optional<Image> changedImage = createSameShape(image);
|
||||
ImageProcessing.changeLuminosity(changedImage, firstParam);
|
||||
BufferedImage bufImg;
|
||||
try {
|
||||
bufImg = ImageIO.read(new ByteArrayInputStream(image.get().getData()));
|
||||
} catch (IOException e) {
|
||||
return new ResponseEntity<>("Image not readable",
|
||||
HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
InputStream inputStream = new ByteArrayInputStream(changedImage.get().getData());
|
||||
return ResponseEntity.ok().contentType(MediaType.IMAGE_JPEG).body(new InputStreamResource(inputStream));
|
||||
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);
|
||||
}
|
||||
return new ResponseEntity<>("Image id=" + id + " not found.", HttpStatus.NOT_FOUND);
|
||||
|
||||
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;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import boofcv.io.image.UtilImageIO;
|
||||
import boofcv.io.image.ConvertBufferedImage;
|
||||
import boofcv.struct.image.GrayU8;
|
||||
import boofcv.struct.border.BorderType;
|
||||
import boofcv.struct.image.Planar;
|
||||
|
||||
public class ImageProcessing {
|
||||
@@ -127,7 +123,6 @@ public class ImageProcessing {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* Passe un pixel de l'espace de couleurs RGB à l'espace de couleurs HSV :
|
||||
@@ -277,9 +272,6 @@ public class ImageProcessing {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Applique un filtre moyenneur de taille indiquée à l'image
|
||||
* 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