Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert negative image to positive [closed]

Tags:

java

c++

image

I have old negative films I have scanned onto my computer. I want to write a small program to convert the negative Images to its positive state.

I know there are several image editor applications out there which I can use to achieve this conversion, but I am researching on how to manipulate the pixels to convert them myself via a small app.

Can anyone give me a head start on this? Sample code if possible will also be much appreciated.

like image 670
Bitmap Avatar asked Dec 28 '11 23:12

Bitmap


People also ask

How do I change a negative picture to a positive?

Open the photo in Windows Paint and go to... Image / Invert Colors...or just type...Ctrl+I. will launch that has the Invert Color option. it has an option for reversing a negative.

How do I convert old negatives to digital photos?

The best way to digitize negatives and slides is to use a film and slide scanner. These devices are similar to regular scanners, but they're specifically designed to scan negatives and slides that need to be backlit to view.

How do you remove negatives from photos?

Please check the Android Settings-> Accessibility:->Colour inversion or Colour correction, which could need turning off. Your device may have different choices so check if there any other options you think might affect your photos.


Video Answer


1 Answers

I just wrote up a working example. Given the following input image img.png.

img.png

The output will be a new image invert-img.png like

invert-img.png

import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;

class Convert
{
    public static void main(String[] args)
    {
        invertImage("img.png");
    }

    public static void invertImage(String imageName) {
        BufferedImage inputFile = null;
        try {
            inputFile = ImageIO.read(new File(imageName));
        } catch (IOException e) {
            e.printStackTrace();
        }

        for (int x = 0; x < inputFile.getWidth(); x++) {
            for (int y = 0; y < inputFile.getHeight(); y++) {
                int rgba = inputFile.getRGB(x, y);
                Color col = new Color(rgba, true);
                col = new Color(255 - col.getRed(),
                                255 - col.getGreen(),
                                255 - col.getBlue());
                inputFile.setRGB(x, y, col.getRGB());
            }
        }

        try {
            File outputFile = new File("invert-"+imageName);
            ImageIO.write(inputFile, "png", outputFile);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

If you want to create a monochrome image, you can alter the calculation of col to something like this:

int MONO_THRESHOLD = 368;
if (col.getRed() + col.getGreen() + col.getBlue() > MONO_THRESHOLD)
    col = new Color(255, 255, 255);
else
    col = new Color(0, 0, 0);

The above will give you the following image

monochromic-img.png

You can adjust MONO_THRESHOLD to get a more pleasing output. Increasing the number will make the pixel darker and vice versa.

like image 172
kba Avatar answered Oct 16 '22 15:10

kba