现在小弟在做遥感专题信息提取程序,但小弟VC太烂了,不知道算法,所以求高手能提供点代码参考下,拜谢!邮箱 [email protected] ,图像是固定的一张,分类信息已经确定。解决后马上给分!稍微能提供点思路算法的就给分!

解决方案 »

  1.   

    我对遥感一窍不通,呵呵,如果要是逐个的分析象素,可以先将图片保存为BMP,或者是通过使用GDI+或者是CxImage库转换为BMP,然后使用下面的参考下面的函数就可以获得BMP的每个象素点的RGB值了!
    void CCreateRandomBMPDlg::OnBtnTest()
    {
    // TODO: Add your control notification handler code here
    HBITMAP hBmp; CFileDialog dlg(TRUE, "bmp", NULL, 0, "位图文件 (*.bmp)|*.bmp||", this); if (dlg.DoModal() != IDOK)
    {
    return;
    } hBmp = (HBITMAP) LoadImage(NULL, dlg.GetPathName(), IMAGE_BITMAP, 0, 0,
    LR_LOADFROMFILE | LR_CREATEDIBSECTION); if (hBmp == NULL)
    {
    return;
    } BITMAP bm;
    PBITMAPINFO bmpInf; if (GetObject(hBmp, sizeof(bm), &bm) == 0)
    return ; int nPaletteSize = 0; if (bm.bmBitsPixel < 16)
    nPaletteSize = (int) pow(2, bm.bmBitsPixel); bmpInf = (PBITMAPINFO) LocalAlloc(LPTR,
    sizeof(BITMAPINFOHEADER) +
    sizeof(RGBQUAD) * nPaletteSize); //-----------------------------------------------
    bmpInf->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
    bmpInf->bmiHeader.biWidth = bm.bmWidth;
    bmpInf->bmiHeader.biHeight = bm.bmHeight;
    bmpInf->bmiHeader.biPlanes = bm.bmPlanes;
    bmpInf->bmiHeader.biBitCount = bm.bmBitsPixel;
    bmpInf->bmiHeader.biCompression = BI_RGB;
    bmpInf->bmiHeader.biSizeImage = (bm.bmWidth + 7) /
    8 * bm.bmHeight * bm.bmBitsPixel;
    bmpInf->bmiHeader.biXPelsPerMeter = 0;
    bmpInf->bmiHeader.biYPelsPerMeter = 0;
    bmpInf->bmiHeader.biClrUsed = 0;
    bmpInf->bmiHeader.biClrImportant = 0;
    //----------------------------------------------- HDC hDC = ::GetWindowDC(NULL);
    if (!::GetDIBits(hDC, hBmp, 0, (WORD) bm.bmHeight, NULL, bmpInf,
    DIB_RGB_COLORS))
    {
    LocalFree(bmpInf);
    ::ReleaseDC(NULL, hDC);
    return ;
    } void* buf = (void*) new char[bmpInf->bmiHeader.biSizeImage];
    if (buf == NULL)
    {
    ::ReleaseDC(NULL, hDC);
    LocalFree(bmpInf);
    return ;
    } if (!::GetDIBits(hDC, hBmp, 0, (UINT) bm.bmHeight, buf, bmpInf,
    DIB_RGB_COLORS))
    {
    ::ReleaseDC(NULL, hDC);
    delete[]buf;
    LocalFree(bmpInf);
    return ;
    } ::ReleaseDC(NULL, hDC); CString sMsg;
    sMsg.Format("BitsPixel:%d,width:%d,height:%d", bm.bmBitsPixel, bm.bmWidth,
    bm.bmHeight); AfxMessageBox(sMsg); CClientDC dc(this); if (bm.bmBitsPixel == 8)
    {
    BYTE* pData = (BYTE*) buf; int nWidth = bm.bmWidth;
    while (nWidth % 4 != 0)
    {
    //Bmp每行数据都是4个字节的整数倍。
    nWidth++;
    } for (int i = 0; i < bm.bmHeight; i++)
    {
    for (int j = 0; j < bm.bmWidth; j++)
    {
    RGBQUAD rgbQ;
    rgbQ = bmpInf->bmiColors[pData[i * nWidth + j]];
    dc.SetPixel(j, bm.bmHeight - i,
    RGB(rgbQ.rgbRed, rgbQ.rgbGreen, rgbQ.rgbBlue));
    }
    }
    }
    else if (bm.bmBitsPixel == 16)
    {
    BYTE* pData = (BYTE*) buf; int nWidth = bm.bmWidth*2;
    while (nWidth % 4 != 0)
    {
    nWidth++;
    } BYTE red, green, blue; for (int i = 0; i < bm.bmHeight; i++)
    {
    for (int j = 0; j < bm.bmWidth; j++)
    {
    blue = pData[i * nWidth + j * 2] & 0x1F;
    green = pData[i * nWidth + j * 2] >> 5;
    green |= (pData[i * nWidth + j * 2 + 1] & 0x03) << 3;
    red = (pData[i * nWidth + j * 2 + 1] >> 2) & 0x1F; WORD wRed = red*8;
    WORD wBlue = blue*8;
    WORD wGreen = green*8; red = min(255, wRed);
    blue = min(255, wBlue);
    green = min(255, wGreen); dc.SetPixel(j, bm.bmHeight - i, RGB(red, green, blue));
    }
    }
    }
    else if (bm.bmBitsPixel == 24)
    {
    BYTE* pData = (BYTE*) buf; int nWidth = bm.bmWidth*3;
    while (nWidth % 4 != 0)
    {
    nWidth++;
    } for (int i = 0; i < bm.bmHeight; i++)
    {
    for (int j = 0; j < bm.bmWidth; j++)
    {
    dc.SetPixel(j, bm.bmHeight -
    i,
    RGB(pData[i * nWidth + j * 3 + 2],
    pData[i * nWidth + j * 3 + 1],
    pData[i * nWidth + j * 3]));
    }
    }
    }
    else if (bm.bmBitsPixel == 32)
    {
    BYTE* pData = (BYTE*) buf; int nWidth = bm.bmWidth*4; for (int i = 0; i < bm.bmHeight; i++)
    {
    for (int j = 0; j < bm.bmWidth; j++)
    {
                                        //注意RGB值是怎么获得的
    dc.SetPixel(j, bm.bmHeight -
    i,
    RGB(pData[i * nWidth + j * 4 + 2],
    pData[i * nWidth + j * 4 + 1],
    pData[i * nWidth + j * 4]));
    }
    }
    } delete[]buf; DeleteObject(hBmp);
    LocalFree(bmpInf);
    }
      

  2.   

    CxImage
    http://www.codeproject.com/bitmap/cximage.aspCxImage Sample
    http://www.codeproject.com/listctrl/ThumbsViewer.aspGDI+ Sample
    http://www.codeproject.com/vcpp/gdiplus/GdiPThumbnailsViewer.asp
    http://www.vckbase.com/document/viewdoc/?id=1177
      

  3.   

    这里肯定有你想要的 ^o^
    http://www.vckbase.com/code/listcode.asp?mclsid=7&sclsid=715
      

  4.   

    BMP文件的提前函数我们老师已经给了,让做的就是一个小case,图片就是任意一张,(当然我们做时要固定它了),上面有条路或是有条江,然后把这条路或是江给提出来换种颜色显示出来
    大概就是这样了,各位大虾帮忙了小弟只会VB和ASP,C,不会VC,郁闷了
      

  5.   

    修改象素信息参考:
    void CCreateRandomBMPDlg::OnBtnCreateBMP()
    {
    CDC dc;
    dc.CreateDC("DISPLAY", NULL, NULL, NULL);
    CBitmap bm;
    int Width = 800;//指定图片宽度
    int Height = 600;//指定图片高度
    bm.CreateCompatibleBitmap(&dc, Width, Height);
    CDC tdc;
    tdc.CreateCompatibleDC(&dc);
    CBitmap* pOld = tdc.SelectObject(&bm);
    tdc.BitBlt(0, 0, Width, Height, &dc, 0, 0, SRCCOPY);
    tdc.SelectObject(pOld); BITMAP btm;
    bm.GetBitmap(&btm);
    DWORD size = btm.bmWidthBytes* btm.bmHeight;
    LPSTR lpData = (LPSTR) GlobalAllocPtr(GPTR, size);
    /////////////////////////////////////////////
    /////////////////////////////////////////////
    BITMAPINFOHEADER bih;
    bih.biBitCount = btm.bmBitsPixel;
    bih.biClrImportant = 0;
    bih.biClrUsed = 0;
    bih.biCompression = 0;
    bih.biHeight = btm.bmHeight;
    bih.biPlanes = 1;
    bih.biSize = sizeof(BITMAPINFOHEADER);
    bih.biSizeImage = size;
    bih.biWidth = btm.bmWidth;
    bih.biXPelsPerMeter = 0;
    bih.biYPelsPerMeter = 0;
    ///////////////////////////////////
    GetDIBits(dc, bm, 0, bih.biHeight, lpData, (BITMAPINFO *) &bih,
    DIB_RGB_COLORS);
    // bm.GetBitmapBits(size,lpData); //此函数在处理5-5-5模式的16位色下会出现颜色混乱
    //////////////////////////////
    //修改RGB值
    int nWidth = btm.bmWidth * 4;
    for (int i = 0; i < btm.bmHeight; i++)
    {
    for (int j = 0; j < btm.bmWidth; j++)
    {
    lpData[i * nWidth + j * 4 + 2] = GetRandomRGBValue(); //R
    lpData[i * nWidth + j * 4 + 1] = GetRandomRGBValue(); //G
    lpData[i * nWidth + j * 4] = GetRandomRGBValue(); //B
    TRACE("\nR = %d; G = %d; B = %d\n",
    lpData[i * nWidth + j * 4 + 2],
    lpData[i * nWidth + j * 4 + 1], lpData[i * nWidth + j * 4]);
    }
    } static int filecount = 0;
    CString name;
    name = "D:\\Test.bmp";//m_Path+name;
    BITMAPFILEHEADER bfh;
    bfh.bfReserved1 = bfh.bfReserved2 = 0;
    bfh.bfType = ((WORD) ('M' << 8) | 'B');
    bfh.bfSize = 54 + size;
    bfh.bfOffBits = 54; CFile bf;
    if (bf.Open(name, CFile::modeCreate | CFile::modeWrite))
    {
    bf.WriteHuge(&bfh, sizeof(BITMAPFILEHEADER));
    bf.WriteHuge(&bih, sizeof(BITMAPINFOHEADER));
    bf.WriteHuge(lpData, size);
    bf.Close();
    }
    GlobalFreePtr(lpData);
    AfxMessageBox("Create BMP File Over!");
    }
    其中使用到的GetRandomRGBValue是一个返回随机RGB值的函数在0到255之间,你可以换成你的设置一种固定的RGB值即可!
      

  6.   

    你要的是算法还是VC的使用说明?
    算法就很多了。告诉你的是:数字图象的算法针对性很强,不同的图象,使用的算法个不相同,对阈值的设定很有讲究。这个在短时间内给不了你的。(你做遥感图象处理的,这些算法都应该知道饿)
    要是vc的使用,那也不是1、2天就会的(不知道你要用MFC么?)。