0

I am working with a square .fits image which displays a circular image fitted inside. I want to iterate through each pixel in this image and print the "bad" pixels onto a text file generated by the code. "Bad" pixels are ones which fall in the edges outside of the circle. As of now, my problem lies in actually calling up the image and reading pixels from it. Since I will need to run this code for a few hundred images, I want to be able to easily summon each image in IRAF and have my code print out the "bad" pixel coordinates.

Here is what I have so far:

#include <iostream>
#include <fstream>
#include <math.h>
using namespace std;

int main() {

    // Open the file in write mode.
    ofstream outputFile;
    outputFile.open ("CCDmask.txt");

    // Set dimensions and important point locations.
    int xDimension = 1481;
    int yDimension = 1469;

    double xCenter = ;
    double yCenter = ;

    double xCircum = 60;
    double yCircum = 1000;

    // Calculate radius of image.
    double radius = sqrt( pow(xCircum-xCenter,2) + pow(yCircum-yCenter,2) );

    // Iterate through pixels.
    for (int x = 1; x <= xDimension; x++) {
        for (int y = 1; y <= yDimension; y++) {
            // Calculate distance between each new point and center.
            double distance = sqrt( pow(x-xCenter,2) + pow(y-yCenter,2) );
            // Print bad pixels.
            if (distance > radius) {
                outputFile << "(" << x << "," << y << ")" << '\n';
            }
        }
    }

    // Close the file.
    outputFile.close();

    return 0;
}

For reference this is what each image I will edit looks like: starsstarsstars

Though it is necessary to load the image itself, I also need to access the coordinates. I'm not sure how the pixel's coordinates get translated in.

  • Excuse me, but what is the problem/question? – Khalil Khalaf Jul 29 '16 at 15:48
  • How do I have the code read in the image to take x and y coordinates from it? There is no point in the code I really access the image, and I think I need to – Michelle Gurevich Jul 29 '16 at 15:53
  • Please do some research. Basic google search got me this very easy and simple code for [**C/C++ Image Loading**](http://stackoverflow.com/questions/3284498/c-c-image-loading) – Khalil Khalaf Jul 29 '16 at 15:55
  • You will need to detect the circle by the way, before processing it. You can use this very strong library that will allow you to even detect **partial** circles in an image, look up [**OpenCV**](https://www.google.com/webhp?sourceid=chrome-instant&rlz=1C1GIVA_enUS679US679&ion=1&espv=2&ie=UTF-8#q=opencv%20detect%20partial%20circles). – Khalil Khalaf Jul 29 '16 at 16:05
  • I searched for hours but didn't find anything. Hadn't realized it was called loading the image. Thank you for the link, it is very appreciated – Michelle Gurevich Jul 29 '16 at 16:08
  • Welcome to Stack Overflow then. Please be advised that **many** users fall in the same problem where they don't know what a certain task is "called". So you will probably find many duplicate questions who are using literal words like the one you used in your question. Which got me this: [**Read in the image and access it c++ - Result**](https://www.google.com/webhp?sourceid=chrome-instant&rlz=1C1GIVA_enUS679US679&ion=1&espv=2&ie=UTF-8#q=read%20in%20image%20and%20access%20it%20c%2B%2B) with "_**About 1,470,000 results (in 0.55 seconds)**_" – Khalil Khalaf Jul 29 '16 at 16:14
  • I still don't understand how having opened the image I can access the coordinates of a pixel – Michelle Gurevich Jul 29 '16 at 16:22

0 Answers0