Loading [MathJax]/extensions/tex2jax.js
Logo ROOT   6.08/07
Reference Guide
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
rose_image.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_image
3 /// \notebook
4 /// Display image in a new canvas and pad.
5 ///
6 /// \macro_image
7 /// \macro_code
8 ///
9 /// \author Valeriy Onuchin
10 
11 #include "TImage.h"
12 #include "TCanvas.h"
13 #include "TArrayD.h"
14 #include "TROOT.h"
15 #include "TColor.h"
16 #include "TAttImage.h"
17 #include "TEnv.h"
18 
19 TCanvas *c1;
20 
21 void rose_image()
22 {
23  TImage *img = TImage::Open("$ROOTSYS/tutorials/image/rose512.jpg");
24 
25  if (!img) {
26  printf("Could not create an image... exit\n");
27  return;
28  }
29 
30  img->SetConstRatio(0);
32 
33  TString fp = gEnv->GetValue("Root.TTFontPath", "");
34  TString bc = fp + "/BlackChancery.ttf";
35  TString ar = fp + "/arial.ttf";
36 
37  // draw text over image with funny font
38  img->DrawText(120, 160, "Hello World!", 32,
39  gROOT->GetColor(4)->AsHexString(),
41 
42  // draw text over image with foreground specified by pixmap
43  img->DrawText(250, 350, "goodbye cruel world ...", 24, 0,
44  ar, TImage::kPlain, "fore.xpm");
45 
46  TImage *img2 = TImage::Open("mditestbg.xpm");
47 
48  // tile image
49  img2->Tile(img->GetWidth(), img->GetHeight());
50 
51  c1 = new TCanvas("rose512", "examples of image manipulations", 760, 900);
52  c1->Divide(2, 3);
53  c1->cd(1);
54  img->Draw("xxx");
55  img->SetEditable(kTRUE);
56 
57  c1->cd(2);
58  // averaging with mditestbg.xpm image
59  TImage *img3 = (TImage*)img->Clone("img3");
60  img3->Merge(img2, "allanon");
61  img3->Draw();
62 
63  // contrasting (tint with itself)
64  c1->cd(3);
65  TImage *img4 = (TImage*)img->Clone("img4");
66  img4->Merge(img4, "tint");
67 
68  // draw filled rectangle with magenta color
69  img4->FillRectangle("#FF00FF", 20, 220, 40, 40);
70 
71  // Render multipoint alpha-blended gradient (R->G->B)
72  img4->Gradient(0, "#FF0000 #00FF00 #220000FF", 0, 50, 50, 100, 100);
73 
74  // draw semi-transparent 3D button
75  img4->Bevel(300, 20, 160, 40, "#ffffffff", "#fe000000", 3, 0);
76  img4->DrawLine(10, 100, 100, 10, "#0000ff", 4);
77  img4->Draw();
78 
79  // vectorize image. Reduce palette to 256 colors
80  c1->cd(4);
81  TImage *img5 = (TImage*)img->Clone("img5");
82  img5->Vectorize(256);
83  img5->Draw();
84 
85  // quantization of the image
86  c1->cd(5);
87  TImage *img6 = (TImage*)img->Clone("img6");
88  TImagePalette *pal = (TImagePalette *)&img5->GetPalette();
89  TArrayD *arr = img6->GetArray(50, 40, pal);
90  img6->SetImage(arr->GetArray(), 50, 40, pal);
91  img6->Draw();
92 
93  // HSV adjustment (convert red to yellow)
94  c1->cd(6);
95  TImage *img7 = (TImage*)img->Clone("img7");
96  img7->HSV(0, 40, 40);
97  img7->Draw();
98 }
virtual UInt_t GetHeight() const
Definition: TImage.h:237
return c1
Definition: legend1.C:41
virtual UInt_t GetWidth() const
Definition: TImage.h:236
const Double_t * GetArray() const
Definition: TArrayD.h:45
virtual void SetConstRatio(Bool_t constRatio=kTRUE)
Set (constRatio = kTRUE) or unset (constRadio = kFALSE) the ratio flag.
Definition: TAttImage.cxx:641
TVirtualPad * cd(Int_t subpadnumber=0)
Set current canvas & pad.
Definition: TCanvas.cxx:659
virtual Double_t * Vectorize(UInt_t=256, UInt_t=4, Int_t=0)
Definition: TImage.h:169
#define gROOT
Definition: TROOT.h:364
Basic string class.
Definition: TString.h:137
virtual void Draw(Option_t *option="")
Default Draw method for all objects.
Definition: TObject.cxx:255
An abstract interface to image processing library.
Definition: TImage.h:37
virtual void Merge(const TImage *, const char *="alphablend", Int_t=0, Int_t=0)
Definition: TImage.h:180
virtual void SetImageQuality(EImageQuality lquality)
Definition: TAttImage.h:105
virtual void SetImage(const Double_t *, UInt_t, UInt_t, TImagePalette *=0)
Definition: TImage.h:124
virtual void FillRectangle(const char *=0, Int_t=0, Int_t=0, UInt_t=0, UInt_t=0)
Definition: TImage.h:200
virtual void Bevel(Int_t=0, Int_t=0, UInt_t=0, UInt_t=0, const char *="#ffdddddd", const char *="#ff555555", UShort_t=1, Bool_t=kFALSE)
Definition: TImage.h:186
virtual const TImagePalette & GetPalette() const
Definition: TAttImage.h:94
virtual Int_t GetValue(const char *name, Int_t dflt)
Returns the integer value for a resource.
Definition: TEnv.cxx:496
virtual TObject * Clone(const char *) const
Make a clone of an object using the Streamer facility.
Definition: TImage.h:119
virtual void SetEditable(Bool_t=kTRUE)
Definition: TImage.h:233
The Canvas class.
Definition: TCanvas.h:41
virtual void DrawText(Int_t=0, Int_t=0, const char *="", Int_t=12, const char *=0, const char *="fixed", EText3DType=TImage::kPlain, const char *=0, Float_t=0)
Definition: TImage.h:208
R__EXTERN TEnv * gEnv
Definition: TEnv.h:174
virtual TArrayD * GetArray(UInt_t=0, UInt_t=0, TImagePalette *=gWebImagePalette)
Definition: TImage.h:242
A class to define a conversion from pixel values to pixel color.
Definition: TAttImage.h:39
Array of doubles (64 bits per element).
Definition: TArrayD.h:29
virtual void DrawLine(UInt_t, UInt_t, UInt_t, UInt_t, const char *="#000000", UInt_t=1)
Definition: TImage.h:192
virtual void Gradient(UInt_t=0, const char *="#FFFFFF #000000", const char *=0, Int_t=0, Int_t=0, UInt_t=0, UInt_t=0)
Definition: TImage.h:176
virtual void Divide(Int_t nx=1, Int_t ny=1, Float_t xmargin=0.01, Float_t ymargin=0.01, Int_t color=0)
Automatic pad generation by division.
Definition: TPad.cxx:1089
static TImage * Open(const char *file, EImageFileTypes type=kUnknown)
Open a specified image file.
Definition: TImage.cxx:110
virtual void HSV(UInt_t=0, UInt_t=360, Int_t=0, Int_t=0, Int_t=0, Int_t=0, Int_t=0, UInt_t=0, UInt_t=0)
Definition: TImage.h:172
const Bool_t kTRUE
Definition: Rtypes.h:91
virtual void Tile(UInt_t, UInt_t)
Definition: TImage.h:156