代码之家  ›  专栏  ›  技术社区  ›  PerlDev

如果我们只有图像,如何发现面积图数据?

  •  1
  • PerlDev  · 技术社区  · 14 年前

    1 回复  |  直到 14 年前
        1
  •  1
  •   sum1stolemyname    14 年前

    如果你知道y轴的刻度,这应该是可能的。

    鉴于

    • 坐标x,y处的像素
    • 图表原点的偏移量,以图像像素xoffset,yoffset为单位
    • 你的坐标轴的刻度是X轴刻度,Y轴刻度

    你可以计算这个像素的数据(伪代码)

    pixelData.x := (x - xoffset) * xscale
    pixeldata.y := (y - yoffset) * yscale
    

    //set up desired color levels to filter out
    redmin := 240;
    redmax := 255
    bluemin := 0;
    bluemax := 0;
    greenmin := 0
    greenmax := 0;
    
    //load source bitmap
    myBitmap := LoadBitmap("Chartfile.bmp");
    
    //loop over bitmap pixels
    for iX := 0 to myBitmap.width-1 do
      for iY := 0 myBitmap.height-1 do
        begin  
          myColorVal := myBitmap.GetPixels(iX, iY);
          //if the pixel color is inside your target color range, store it
          if ((mycolorVal.r >=redmin) and (myColorVal.r <= redmax)) and
             ((mycolorVal.g >=greenmin) and (myColorVal.g <= greenmax)) and
             ((mycolorVal.b >=bluemin) and (myColorVal.b <= bluemax)) then 
             storeDataValue(iX, iY); //performs the value scaling operation mentioned above
        end;