{
"cells": [
{
"cell_type": "markdown",
"id": "94266d2f",
"metadata": {},
"source": [
"# rose_image\n",
"Display image in a new canvas and pad.\n",
"\n",
"\n",
"\n",
"\n",
"**Author:** Valeriy Onuchin \n",
"This notebook tutorial was automatically generated with ROOTBOOK-izer from the macro found in the ROOT repository on Tuesday, May 19, 2026 at 08:38 PM."
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "ba274cb3",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:38:47.204055Z",
"iopub.status.busy": "2026-05-19T20:38:47.203943Z",
"iopub.status.idle": "2026-05-19T20:38:47.226526Z",
"shell.execute_reply": "2026-05-19T20:38:47.225930Z"
}
},
"outputs": [],
"source": [
"%%cpp -d\n",
"#include \"TImage.h\"\n",
"#include \"TCanvas.h\"\n",
"#include \"TArrayD.h\"\n",
"#include \"TROOT.h\"\n",
"#include \"TColor.h\"\n",
"#include \"TAttImage.h\"\n",
"#include \"TEnv.h\"\n",
"\n",
"TCanvas *c1;"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "526b7c0e",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:38:47.228037Z",
"iopub.status.busy": "2026-05-19T20:38:47.227918Z",
"iopub.status.idle": "2026-05-19T20:38:47.553917Z",
"shell.execute_reply": "2026-05-19T20:38:47.553460Z"
}
},
"outputs": [],
"source": [
"TString dir = TROOT::GetTutorialDir();\n",
"\n",
"TImage *img = TImage::Open(dir + \"/visualisation/image/rose512.jpg\");\n",
"\n",
"if (!img) {\n",
" printf(\"Could not create an image... exit\\n\");\n",
" return;\n",
"}\n",
"\n",
"img->SetConstRatio(false);\n",
"img->SetImageQuality(TAttImage::kImgBest);\n",
"\n",
"TString bc = \"BlackChancery.ttf\";\n",
"TString ar = \"arial.ttf\";"
]
},
{
"cell_type": "markdown",
"id": "fbb691c2",
"metadata": {},
"source": [
"draw text over image with funny font"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "3d7014c0",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:38:47.555940Z",
"iopub.status.busy": "2026-05-19T20:38:47.555822Z",
"iopub.status.idle": "2026-05-19T20:38:47.768389Z",
"shell.execute_reply": "2026-05-19T20:38:47.767717Z"
}
},
"outputs": [],
"source": [
"img->DrawText(120, 160, \"Hello World!\", 32, gROOT->GetColor(4)->AsHexString(), bc, TImage::kShadeBelow);"
]
},
{
"cell_type": "markdown",
"id": "dfee6971",
"metadata": {},
"source": [
"draw text over image with foreground specified by pixmap"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "80b5b14e",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:38:47.770375Z",
"iopub.status.busy": "2026-05-19T20:38:47.770259Z",
"iopub.status.idle": "2026-05-19T20:38:47.972845Z",
"shell.execute_reply": "2026-05-19T20:38:47.972141Z"
}
},
"outputs": [],
"source": [
"img->DrawText(250, 350, \"goodbye cruel world ...\", 24, nullptr, ar, TImage::kPlain, dir + \"/image/fore.xpm\");\n",
"\n",
"TImage *img2 = TImage::Open(dir + \"/image/mditestbg.xpm\");"
]
},
{
"cell_type": "markdown",
"id": "b8b8ec50",
"metadata": {},
"source": [
"tile image"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "e9006f7f",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:38:47.974762Z",
"iopub.status.busy": "2026-05-19T20:38:47.974639Z",
"iopub.status.idle": "2026-05-19T20:38:48.188366Z",
"shell.execute_reply": "2026-05-19T20:38:48.187493Z"
}
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Warning in : Image not initiated\n"
]
}
],
"source": [
"img2->Tile(img->GetWidth(), img->GetHeight());\n",
"\n",
"c1 = new TCanvas(\"rose512\", \"examples of image manipulations\", 760, 900);\n",
"c1->Divide(2, 3);\n",
"c1->cd(1);\n",
"img->Draw(\"xxx\");\n",
"img->SetEditable(kTRUE);\n",
"\n",
"c1->cd(2);"
]
},
{
"cell_type": "markdown",
"id": "251a4ac3",
"metadata": {},
"source": [
"averaging with mditestbg.xpm image"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "69aa39d2",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:38:48.189868Z",
"iopub.status.busy": "2026-05-19T20:38:48.189743Z",
"iopub.status.idle": "2026-05-19T20:38:48.402215Z",
"shell.execute_reply": "2026-05-19T20:38:48.401500Z"
}
},
"outputs": [],
"source": [
"TImage *img3 = (TImage *)img->Clone(\"img3\");\n",
"img3->Merge(img2, \"allanon\");\n",
"img3->Draw();"
]
},
{
"cell_type": "markdown",
"id": "337fb716",
"metadata": {},
"source": [
"contrasting (tint with itself)"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "379d935a",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:38:48.403918Z",
"iopub.status.busy": "2026-05-19T20:38:48.403803Z",
"iopub.status.idle": "2026-05-19T20:38:48.611588Z",
"shell.execute_reply": "2026-05-19T20:38:48.610862Z"
}
},
"outputs": [],
"source": [
"c1->cd(3);\n",
"TImage *img4 = (TImage *)img->Clone(\"img4\");\n",
"img4->Merge(img4, \"tint\");"
]
},
{
"cell_type": "markdown",
"id": "60042069",
"metadata": {},
"source": [
"draw filled rectangle with magenta color"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "c8d1b88d",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:38:48.613232Z",
"iopub.status.busy": "2026-05-19T20:38:48.613115Z",
"iopub.status.idle": "2026-05-19T20:38:48.825491Z",
"shell.execute_reply": "2026-05-19T20:38:48.824796Z"
}
},
"outputs": [],
"source": [
"img4->FillRectangle(\"#FF00FF\", 20, 220, 40, 40);"
]
},
{
"cell_type": "markdown",
"id": "2993c25a",
"metadata": {},
"source": [
"Render multipoint alpha-blended gradient (R->G->B)"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "e4ed3a80",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:38:48.827256Z",
"iopub.status.busy": "2026-05-19T20:38:48.827138Z",
"iopub.status.idle": "2026-05-19T20:38:49.039470Z",
"shell.execute_reply": "2026-05-19T20:38:49.038878Z"
}
},
"outputs": [],
"source": [
"img4->Gradient(0, \"#FF0000 #00FF00 #220000FF\", nullptr, 50, 50, 100, 100);"
]
},
{
"cell_type": "markdown",
"id": "cbd2d83a",
"metadata": {},
"source": [
"draw semi-transparent 3D button"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "7b0558a4",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:38:49.041657Z",
"iopub.status.busy": "2026-05-19T20:38:49.041523Z",
"iopub.status.idle": "2026-05-19T20:38:49.253997Z",
"shell.execute_reply": "2026-05-19T20:38:49.253239Z"
}
},
"outputs": [],
"source": [
"img4->Bevel(300, 20, 160, 40, \"#ffffffff\", \"#fe000000\", 3, false);\n",
"img4->DrawLine(10, 100, 100, 10, \"#0000ff\", 4);\n",
"img4->Draw();"
]
},
{
"cell_type": "markdown",
"id": "b9906deb",
"metadata": {},
"source": [
"vectorize image. Reduce palette to 256 colors"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "7e13b04f",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:38:49.256233Z",
"iopub.status.busy": "2026-05-19T20:38:49.256117Z",
"iopub.status.idle": "2026-05-19T20:38:49.468503Z",
"shell.execute_reply": "2026-05-19T20:38:49.467853Z"
}
},
"outputs": [],
"source": [
"c1->cd(4);\n",
"TImage *img5 = (TImage *)img->Clone(\"img5\");\n",
"img5->Vectorize(256);\n",
"img5->Draw();"
]
},
{
"cell_type": "markdown",
"id": "250ee67f",
"metadata": {},
"source": [
"quantization of the image"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "c166b59c",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:38:49.470576Z",
"iopub.status.busy": "2026-05-19T20:38:49.470458Z",
"iopub.status.idle": "2026-05-19T20:38:49.682921Z",
"shell.execute_reply": "2026-05-19T20:38:49.682186Z"
}
},
"outputs": [],
"source": [
"c1->cd(5);\n",
"TImage *img6 = (TImage *)img->Clone(\"img6\");\n",
"TImagePalette *pal = (TImagePalette *)&img5->GetPalette();\n",
"TArrayD *arr = img6->GetArray(50, 40, pal);\n",
"img6->SetImage(arr->GetArray(), 50, 40, pal);\n",
"img6->Draw();"
]
},
{
"cell_type": "markdown",
"id": "2ac1a663",
"metadata": {},
"source": [
"HSV adjustment (convert red to yellow)"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "f90958b7",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:38:49.684665Z",
"iopub.status.busy": "2026-05-19T20:38:49.684537Z",
"iopub.status.idle": "2026-05-19T20:38:49.897037Z",
"shell.execute_reply": "2026-05-19T20:38:49.896278Z"
}
},
"outputs": [],
"source": [
"c1->cd(6);\n",
"TImage *img7 = (TImage *)img->Clone(\"img7\");\n",
"img7->HSV(0, 40, 40);\n",
"img7->Draw();"
]
},
{
"cell_type": "markdown",
"id": "ad3f7b9b",
"metadata": {},
"source": [
"Draw all canvases "
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "d47a7b01",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:38:49.898503Z",
"iopub.status.busy": "2026-05-19T20:38:49.898389Z",
"iopub.status.idle": "2026-05-19T20:38:50.243756Z",
"shell.execute_reply": "2026-05-19T20:38:50.242866Z"
}
},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"\n",
"
\n",
"\n",
"\n",
"\n"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"gROOT->GetListOfCanvases()->Draw()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "ROOT C++",
"language": "c++",
"name": "root"
},
"language_info": {
"codemirror_mode": "text/x-c++src",
"file_extension": ".C",
"mimetype": " text/x-c++src",
"name": "c++"
}
},
"nbformat": 4,
"nbformat_minor": 5
}