Click here to Skip to main content
16,020,567 members
Please Sign up or sign in to vote.
1.00/5 (4 votes)
See more:
I'm making an application to crop the image
cut out objects in the image automatically
This link to image : http://gunk-rico.deviantart.com/art/cancer-193284261[^]
and its object is the cancer lesions. I've made a code to cut the image manually when I create a code for cutting the images automatically, I have difficulty in determining the ends of the object coordinate. How do I determine the coordinates of the outermost tip of the object? The following is my code:

C#
x0 = 0;
y0 = 0;
xmax = 0;
ymax = 0;
// GDI+ still lies to us - the return format is BGR, NOT RGB.
BitmapData bmData = EditImage.LockBits(new Rectangle(0, 0, EditImage.Width, EditImage.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);

int stride = bmData.Stride;
System.IntPtr Scan0 = bmData.Scan0;

unsafe
{
    byte* p = (byte*)(void*)Scan0;
    int nOffset = stride - EditImage.Width * 3;                

    for (int y = 0; y < EditImage.Height; ++y)
    {
        for (int x = 0; x < EditImage.Width; ++x)
        {
            if ((y == 0) && (x == 0))
            {
                awalB = p[0];
                awalG = p[1];
                awalR = p[2];
            }
            else
            {
                if ((awalB == p[0]) && (awalG == p[1]) && (awalR == p[2]))
                {
                }
                else if (x0 == 0)
                {
                    x0 = x;
                }
                else
                {
                    xmax = x;
                }
            }
            p += 3;
        }
        p += nOffset;
    }
}

unsafe
{
    byte* p = (byte*)(void*)Scan0;
    int nOffset = stride - EditImage.Height * 3;

    for (int x = 0; x < EditImage.Width; ++x)
    {
        for (int y = 0; y < EditImage.Height; ++y)
        {
            if ((y == 0) && (x == 0))
            {
                awalB = p[0];
                awalG = p[1];
                awalR = p[2];
            }
            else
            {
                if ((awalB == p[0]) && (awalG == p[1]) && (awalR == p[2]))
                {
                }
                else if (y0 == 0)
                {
                    y0 = y;
                }
                else
                {
                    ymax = y;
                }
            }
            p += 3;
        }
        p += nOffset;
    }
} 

EditImage.UnlockBits(bmData); 

x1 = xmax - x0;
y1 = ymax - y0;
_selection = new Rectangle(new Point(x0, y0), new Size());
_selection.Width = x1;
_selection.Height = y1; 

// Create cropped image:
Image img = pbox_hasil.Image.Crop(_selection);
// Fit image to the picturebox:
pbox_hasil.Image = img.Fit2PictureBox(pbox_hasil);
Posted
Updated 13-Jan-11 7:33am
v2
Comments
Manfred Rudolf Bihy 13-Jan-11 14:41pm    
There you are again. Reposting the same old question. Please tell me just one thing: Valery tried to help you on one of your previous posts and even said there was a working solution.
1. Did you try it?
2. What was the outcome of your efforts?
3. Why are you not staying with your question and keep on improving on it and communicate with the people that are trying to help you?

Reposting your question again and again is starting to get very annoying.

1 solution

There are about 10 question related to this project. Don't get me wrong, I am not against someone asking many questions.

But what scary me the most is that you mentioned in your description, this is for a project related to cancer. Cancer is a disease that I don't wish it to my worst enemy. But if it strikes someone, they should get all available treatment/diagnosis.

If you are truly working on Cancer application and you seem to be clue less on many levels, it scares me to hell, who will use your application. I hope you don't screw up things and bring more misery to those who are afflicted with the worst disease.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900