MathGroup Archive 1997

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: 3D plot of bitmap???

  • To: mathgroup at
  • Subject: [mg8238] Re: [mg8036] 3D plot of bitmap???
  • From: dreece at (Daryl Reece)
  • Date: Thu, 21 Aug 1997 21:16:54 -0400
  • Organization: MindSpring Enterprises, Inc.
  • Sender: owner-wri-mathgroup at

There is a way to read a monochrome bitmap in directly.  I did it
using the following code.  There are a few points to note.
1) The user must supply the vertical and horizontal resolution of the
2) The bitmap file is contained in tek00000.bmp for this case.
3) The bitmap is read in using the first 2 steps.  The remainder of
steps are to replace multiple y values with a single value, scale the
data and generate an interpolating function.

If anyone knows how to extract the resolution of a bitmap from the
header, I would like to know.

(* Bitmap Parameters *)
HorRes = 640;
VerRes = 480;
BitsPerByte = 8;

(* Read In Data *)
data=Partition[Take[ReadList["tek00000.bmp", Byte],
                    -VerRes*HorRes/BitsPerByte], HorRes/BitsPerByte];

(* Convert Byte Pixel Data to X-Y Data *)
listdata= (Reverse[#]& /@ Position[Flatten[IntegerDigits[#,2]]& /@
data, 0]);

(* Sort Points Based on X Coordinate *)
sortdata = Sort[listdata, (#2[[1]]>#1[[1]])&];

(* Starting Coordinates of Curve *)

(* Peak of Curve *)

(* Replace Multiple Y Values on Single X Value With the Average *)
  lens=(Length[Position[Transpose[dat][[1]],#]]& /@ xs);
  nddat=Sort[nddat, (#2[[1]]>#1[[1]])&];

(* Non Duplicated Data *)
nodupdata = RemoveDups[sortdata];

(* Scaling Routine *)
(* Linearly scale pixel coordinates to actual values using coordinates

    of two points on curve *)
ScaleData[x_, {xtmax_,xfmax_}, {xtmin_,xfmin_}] :=
   (xtmax-xtmin)/(xfmax-xfmin) (x-xfmin)+xtmin;

(* Scaled Data *)
scaledata =
 ScaleData[#[[2]],{0.096,385},{0,149}]}& /@ nodupdata;

(* Plot Current Profile *)
ListPlot[scaledata, PlotJoined->True,
 PlotLabel->"PAL Current Consumption",
 AxesLabel->{"Time(s)", "Current(A)"}]

(* Generate Linear Interpolated Function *)
current=Interpolation[scaledata, InterpolationOrder->1]

  • Prev by Date: Re: AW: Saving graphics in Mma 3.0.1
  • Next by Date: Re: Is there really no longer any way to Find cells by cell style?
  • Previous by thread: 3D plot of bitmap???
  • Next by thread: IntegerQ