       Re: 3D plot of bitmap???

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

```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
bitmap
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 *)
-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[])&];

(* Starting Coordinates of Curve *)
sortdata[]

(* Peak of Curve *)
Part[
sortdata,
Flatten[Position[sortdata,Max[Transpose[sortdata][]]]][]
]

(* Replace Multiple Y Values on Single X Value With the Average *)
RemoveDups[dat_]:=
Module[{xs,lens,nddat},
xs=Union[Transpose[dat][]];
lens=(Length[Position[Transpose[dat][],#]]& /@ xs);
nddat=Transpose[dat//.{{hd___,{x_,y1_},{x_,y2_},tl___}->
{hd,{x,y1+y2},tl}}];
nddat=Sort[nddat, (#2[]>#1[])&];
Transpose[{nddat[],nddat[]/lens}]
]

(* 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[#[],{0.00415,439},{0,26}],
ScaleData[#[],{0.096,385},{0,149}]}& /@ nodupdata;

(* Plot Current Profile *)
ListPlot[scaledata, PlotJoined->True,
PlotRange->{{0,0.005},{-0.01,0.1}},
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