{ "cells": [ { "cell_type": "markdown", "id": "9fd2e382", "metadata": {}, "source": [ "# image2hist\n", "Create a 2-D histogram from an image.\n", "\n", "\n", "\n", "\n", "**Author:** Olivier Couet \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": "66a85c4d", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:38:41.051673Z", "iopub.status.busy": "2026-05-19T20:38:41.051548Z", "iopub.status.idle": "2026-05-19T20:38:41.551956Z", "shell.execute_reply": "2026-05-19T20:38:41.551478Z" } }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "Info in : created default TCanvas with name c1\n" ] } ], "source": [ "TASImage image(\"$ROOTSYS/tutorials/visualisation/image/rose512.jpg\");\n", "UInt_t yPixels = image.GetHeight();\n", "UInt_t xPixels = image.GetWidth();\n", "UInt_t *argb = image.GetArgbArray();\n", "\n", "TH2D *h = new TH2D(\"h\", \"Rose histogram\", xPixels, -1, 1, yPixels, -1, 1);\n", "\n", "for (int row = 0; row < xPixels; ++row) {\n", " for (int col = 0; col < yPixels; ++col) {\n", " int index = col * xPixels + row;\n", " float grey = float(argb[index] & 0xff) / 256;\n", " h->SetBinContent(row + 1, yPixels - col, grey);\n", " }\n", "}\n", "\n", "gStyle->SetPalette(kCubehelix);\n", "h->Draw(\"colz\");" ] }, { "cell_type": "markdown", "id": "15238072", "metadata": {}, "source": [ "Draw all canvases " ] }, { "cell_type": "code", "execution_count": 2, "id": "d191c9b2", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:38:41.555336Z", "iopub.status.busy": "2026-05-19T20:38:41.555204Z", "iopub.status.idle": "2026-05-19T20:38:42.369194Z", "shell.execute_reply": "2026-05-19T20:38:42.368506Z" } }, "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 }