You are not logged in.

#1 2009-04-16 02:10:08

wankel
Member
From: Iowa, USA
Registered: 2008-05-30
Posts: 218
Website

looking for some advice regarding an image related program

Hi fellas, Im looking for some guidance here. I want to write a program that will read an image (image will be an xray image of a square), convert the image to black and white, and measure the length and width of the square. Im looking for the best progamming langauge to make this happen. Anyone have any recommendations? I know c++ has a good imaging library that would be helpful so im looking into that at the moment. And Im pretty sure I can do this with matlab, but Im writing this program for a doctor so I need it to be portable. Thanks in advance for all the help smile

Cliffnotes:
Whats the best programming language to:
-read an image (of a square)
-convert image to black and white
-measure length/width of square
-GUI would be good but not necessary
-easy to write

Offline

#2 2009-04-16 02:19:14

HashBox
Member
Registered: 2009-01-22
Posts: 271

Re: looking for some advice regarding an image related program

Honestly, this sounds like one of the things Java would be good for. Should be able to find the needed image libraries or API fairly easily, and the language itself should be no barrier if you know C++, and it would be portable as well as having a GUI to work with.

Just throwing ideas out there though, C++ might be better suited for you.

Offline

#3 2009-04-16 15:43:02

Killa B
Member
From: United States
Registered: 2008-10-28
Posts: 42
Website

Re: looking for some advice regarding an image related program

I'll second Java.

It probably has built-in support for loading images, it's very portable (without so much as a recompile needed to run on a different system), and easy GUI support.

Whether it's easy to write depends on what you're used to. If you've used C++ it should come easily to you. If you've used C, it shouldn't be too hard to figure out, since a lot of the syntax is the same (except for the OOP stuff).

Offline

#4 2009-04-16 20:23:14

droog
Member
Registered: 2004-11-18
Posts: 877

Re: looking for some advice regarding an image related program

edit, scratch that i saw you want to write your own program.

Last edited by droog (2009-04-16 20:31:11)

Offline

#5 2009-04-16 23:05:17

wankel
Member
From: Iowa, USA
Registered: 2008-05-30
Posts: 218
Website

Re: looking for some advice regarding an image related program

I have a little experience with matlab and c programming. Im currently looking into java now due to its support for GUIs. Now I have a question regarding the program itself. I wanted it to measure the distance of the square in terms of inches. Now I was thinking about measuring the amount of pixels in an inch until I realized this would vary from screen to screen due to the resolutions. Now is there anyway to get a standardized measurement that would work for any monitor?

Offline

#6 2009-04-17 08:26:14

HashBox
Member
Registered: 2009-01-22
Posts: 271

Re: looking for some advice regarding an image related program

You might want to look in to DPI and what The GIMP does in terms of that, also I found this which might be of use as well: http://en.wikipedia.org/wiki/Pixels_per_inch

Offline

#7 2009-04-24 21:13:42

wankel
Member
From: Iowa, USA
Registered: 2008-05-30
Posts: 218
Website

Re: looking for some advice regarding an image related program

HashBox wrote:

You might want to look in to DPI and what The GIMP does in terms of that, also I found this which might be of use as well: http://en.wikipedia.org/wiki/Pixels_per_inch

Thanks HashBox, I think Im off to a good start on this. First, I wrote the program (majority of it) using matlab, and now Im trying to convert it to C++. So far I have:

#include <stdio.h>
#include "CImg.h"
using namespace cimg_library;

//main program
int main()
{
CImg<double> img("xray.jpg");

//converts the image to black and white
img.RGBtoYCbCr().channel(0).resize(-100,-100,1,3).RGBtoLUT(CImg<>(2,1,1,3).fill(0.0f,255.0f),false); 

//displays image
CImgDisplay display(img,"Black and White");
while (!display.is_closed)
display.wait();

    return 0;
}

So right now, I have the black and white xray image. How do I find out the size of the image using c++? Is there a function for that or do I have to write code to find it manually?


Heres the original matlab code I wrote that Im trying to write my c++ code after:


%read the image
[filename,pathname] = uigetfile('*.*', 'Select an image');

%assign image to film
film=imread(filename);

%threshold the image
level = graythresh(film);

%convert image to black&white using the thresholded value
BW = im2bw(film, level);

%display image
imshow(BW);

SIZE=size(BW);
counter=zeros(1, SIZE(1));
for x=1:SIZE(1)
    for y=1:SIZE(2)
        if (BW(x,y)==1) 
            counter(1,x)=counter(1,x)+1;
        end
    end
end

SUM=0;
lines=0;
for counterarray=1:SIZE(1)
    
    if counter(1,counterarray)>0
        lines=lines+1;
        SUM=counter(1,counterarray)+SUM;
    end
end

Last edited by wankel (2009-04-24 21:15:46)

Offline

#8 2009-04-25 06:42:43

juster
Forum Fellow
Registered: 2008-10-07
Posts: 195

Re: looking for some advice regarding an image related program

I tried to find a method giving the resolution/PPI of the image in CImg but couldn't find it!  Lots of stuff in it has more mathematics than I'm capable of, alot of linear algebra and stuff.  It seems very geared towards mathematical analysis.  Good luck!  Try asking in their forums or switch to another image library?

But I wanted to point out something else.  You don't seem to be too clear on resolutions (pun!).  A resolution is unfortunately used to mean two different things.  In printing it means DPI or dots per inch.  In monitors it somehow, by some horrible accident, can also mean screen dimensions, like hey my monitor is 1467x1000 I'm so great.  Why?  Because monitors don't care about so much about preserving original size, like printing does.

Resolution (PPI, like mentioned in an earlier post) is stored in an image file in order to produce a printable version of the same scale.  Otherwise you would have no clue what the original image's actual size was.  You can have a certain resolution in the image file, another PPI resolution on your screen, and a much much higher DPI resolution on your printer.

In order to have an image measure the same inches as the original you will have to resize it using the original resolution and screen resolution as a ratio.

ratio := screen_res / image_res
x *= ratio
y *= ratio

Personally I would use ImageMagick to convert the image file how I wanted it, save it to a new file (or copy the pixel data somehow) and use a crossplatform GUI library like Qt or Gtk to load/display/play with it along with all the nifty controls I needed.  Or just have imagemagick display it...

Offline

Board footer

Powered by FluxBB