static void GLFWCALL key_handler(int key, int action) { if (!init_done) { return; } //No need to do this for both press and release. if (action == GLFW_RELEASE) return; //Switch histogram type based on keys (Q, W, E, R, T). Show open image dialog (O). switch (key) { case 'Q': if (current_histogram != HISTOGRAM_RGB) { current_histogram = HISTOGRAM_RGB; draw_histogram(HISTOGRAM_RGB); } break; case 'W': if (current_histogram != HISTOGRAM_RED) { current_histogram = HISTOGRAM_RED; draw_histogram(HISTOGRAM_RED); } break; case 'E': if (current_histogram != HISTOGRAM_GREEN) { current_histogram = HISTOGRAM_GREEN; draw_histogram(HISTOGRAM_GREEN); } break; case 'R': if (current_histogram != HISTOGRAM_BLUE) { current_histogram = HISTOGRAM_BLUE; draw_histogram(HISTOGRAM_BLUE); } break; case 'T': if (current_histogram != HISTOGRAM_LUMINANACE) { current_histogram = HISTOGRAM_LUMINANACE; draw_histogram(HISTOGRAM_LUMINANACE); } break; case 'L': if(!opening_file) open_file(); break; } }
void QtHistoTfuncPixmap::draw_functioneditor(QPainter* p) { //draw our histogram draw_histogram(p); if(tfunc_enable) { draw_functioneditoronpixmap(p, &funceditor, Qt::darkGray); } }
int main(void) { float grades[MAX_N_STUDENTS]; int n = load_grades(grades, MAX_N_STUDENTS); int bins[N_BINS]; compute_histogram(bins, n, grades); draw_histogram(bins, N_COLUMNS); return EXIT_SUCCESS; }
static void open_file(void) { OPENFILENAME ofn; TCHAR szFile[MAX_PATH]; TCHAR cur_dir[FILENAME_MAX]; size_t file_len; size_t converted_len = 0; char converted_filename[MAX_PATH]; opening_file = GL_TRUE; szFile[0] = '\0'; szFile[1] = '\0'; //Get current working directory. GetCurrentDirectory(sizeof(TCHAR) * FILENAME_MAX, cur_dir); //Initialize OPENFILENAME memset(&ofn, 0, sizeof(ofn)); ofn.lStructSize = sizeof(ofn); ofn.hwndOwner = NULL; ofn.lpstrFile = szFile; ofn.lpstrFile[0] = '\0'; ofn.nMaxFile = MAX_PATH; ofn.lpstrFilter = TEXT("Images (*.jpg;*.png;*.bmp;*.tga;*.psd)\0*.jpg;*.png;*.bmp;*.tga;*.psd\0"); ofn.lpstrInitialDir = TEXT("Images"); ofn.lpstrTitle = TEXT("Open 512x512 image ..."); ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST; if(GetOpenFileName(&ofn)) { file_len = wcslen(ofn.lpstrFile) + 1; wcstombs_s(&converted_len, converted_filename, file_len, ofn.lpstrFile, _TRUNCATE); if (converted_len != file_len) { play_error_sound(); printf("Error: Can't open unicode paths."); opening_file = GL_FALSE; return; } if(load_image(converted_filename)) { draw_histogram(current_histogram); } } //Set the old working directory. SetCurrentDirectory(cur_dir); opening_file = GL_FALSE; }
int main() { image = cv::imread("Images/Image2.png",CV_LOAD_IMAGE_GRAYSCALE); cv::Mat input_matrix = cv::imread("./Images/Image2.png",CV_LOAD_IMAGE_GRAYSCALE); cv::Mat output_matrix = input_matrix; draw_histogram(input_matrix,"./Histograms/Original_Histogram.png"); cv::medianBlur(input_matrix,output_matrix,9); padding = 0.05*col; cv::copyMakeBorder(image, paddedImage, padding, padding, padding, padding, cv::BORDER_CONSTANT, 0); row = paddedImage.rows; col = paddedImage.cols; std::cout << row << ", " << col << std::endl; runAMF(); cv::imwrite("./Images/MedianBlur_Image.png",output_matrix); cv::imwrite("Images/adaptive.png", resImage); draw_histogram(output_matrix,"./Histograms/MedianBlur_Histogram.png"); draw_histogram(resImage,"./Histograms/Adaptive_Histogram.png"); return 0; }
static void node_composit_exec_view_levels(void *data, bNode *node, bNodeStack **in, bNodeStack **out) { CompBuf* cbuf; CompBuf* histogram; RenderData *rd=data; float mean, std_dev; int bins[256]; int x; if(in[0]->hasinput==0) return; if(in[0]->data==NULL) return; histogram=alloc_compbuf(256, 256, CB_RGBA, 1); cbuf=typecheck_compbuf(in[0]->data, CB_RGBA); /*initalize bins*/ for(x=0; x<256; x++) { bins[x]=0; } /*fill bins */ fill_bins(node, in[0]->data, bins, rd->color_mgt_flag & R_COLOR_MANAGEMENT); /* draw the histogram chart */ draw_histogram(node, histogram, bins); /* calculate the average brightness and contrast */ mean=brightness_mean(node, in[0]->data); std_dev=brightness_standard_deviation(node, in[0]->data, mean); /* Printf debuging ;) printf("Mean: %f\n", mean); printf("Std Dev: %f\n", std_dev); */ if(out[0]->hasoutput) out[0]->vec[0]= mean; if(out[1]->hasoutput) out[1]->vec[0]= std_dev; generate_preview(data, node, histogram); if(cbuf!=in[0]->data) free_compbuf(cbuf); free_compbuf(histogram); }
int main(int argc, char *argv[]) { int table[MAX], n; //Needs to be initialized to 0 so i can add correctly. int frequency[MAXNUMBER] = {0}; //set pointers to them. Not really needed as they are pointers already (technically) int *table_p = table; int *frequency_p = frequency; create_random(table_p); count_frequency(frequency_p, table_p); draw_histogram(frequency_p); return 0; }
void update_form_main_ri_sim() { Char tmp_text[100]; FormPtr form; form = FrmGetActiveForm(); // FrmGetFormPtr(formID_main_ri_sim); StrPrintF(tmp_text, "Alloc: %lu b. #Reg: %lu.", total_alloc*4, region_stack_idx); show_lab(form, labelID_total_alloc, tmp_text); StrPrintF(tmp_text, "#AllocReg: %lu #DeallocReg: %lu", num_alloc_reg, num_dealloc_reg); show_lab(form, labelID_stat1, tmp_text); StrPrintF(tmp_text, "#AllocInReg: %lu #ResetReg: %lu", num_alloc_in_reg, num_reset_reg); show_lab(form, labelID_stat2, tmp_text); StrPrintF(tmp_text, "#DeallocUntil: %lu", num_dealloc_until); show_lab(form, labelID_stat3, tmp_text); draw_histogram(from_idx, to_idx); }
void hw1_init(void) { printf("\nInitializing homework 1 ...\n"); //Set defaults. image_data = NULL; current_histogram = HISTOGRAM_NONE; histogram_data = (GLuint*) calloc(HISTOGRAM_BUCKETS, sizeof(GLuint)); init_done = GL_FALSE; glfwSetWindowTitle("GFX Homework: 1.a"); //Color the histogram background white and upload it. bitmap_fill(&texture_data[2], 255, 255, 255); bitmap_upload(&texture_data[2], textures[2]); //Load the test image. if (!load_image("Images/test.png")) { return; } current_histogram = HISTOGRAM_RGB; draw_histogram(HISTOGRAM_RGB); //Add key callback. glfwSetKeyCallback(key_handler); //Change the window size and OpenGL viewport. glfwSetWindowSize(TEXTURE_WIDTH * 2 + BORDER, TEXTURE_HEIGHT); glViewport(0, 0, TEXTURE_WIDTH * 2 + BORDER, TEXTURE_HEIGHT); //Reset projection matrix. glMatrixMode(GL_PROJECTION); glLoadIdentity(); //Set up orthographic projection. glOrtho(0, TEXTURE_WIDTH * 2 + BORDER, TEXTURE_HEIGHT, 0, -1, 1); //Reset model view matrix. glMatrixMode(GL_MODELVIEW); glLoadIdentity(); //Enable textures globally since we're just drawing two textured quads. glEnable(GL_TEXTURE_2D); printf("DONE!\n"); init_done = GL_TRUE; print_help(); }
// All form-related events are handled here. static Boolean ri_sim_event(EventPtr event){ FormPtr form; int handled = 0; switch (event->eType) { case frmOpenEvent: form = FrmGetActiveForm(); FrmDrawForm(form); draw_histogram(0,region_stack_idx-1); handled = 1; break; case ctlSelectEvent: // A control button was pressed and released. switch (event->data.ctlSelect.controlID) { default: break; } case menuEvent: switch (event->data.menu.itemID) { case menuitemID_about: FrmAlert(alertID_about); handled = 1; break; case menuitemID_card_info: // form = FrmGetActiveForm(); // FrmDeleteForm(form); FrmGotoForm(formID_sys_info); break; } break; case nilEvent: // continue region simulation sim_regs(); update_form_main_ri_sim(); handled = 1; break; } return handled; }
void Plot_Measured_Energy_EMC() { /* sanity check */ assert(NELEMS(energy_levels) <= NELEMS(plot_colors)); SetsPhenixStyle(); gROOT->SetBatch(kTRUE); /* * Base Histogram (Recreated from Matching Plots) */ TH1F *const h_base = new TH1F("h_base", "", 100, 0.0, 25); std::vector < TCanvas * >particle_canvases; for (int i = 0; i < nparticles; ++i) { TCanvas *const c = new TCanvas(generate_canvas_name(particles[i]), generate_canvas_title(particles[i]), gStyle->GetCanvasDefW() * ndetectors, gStyle->GetCanvasDefH()); c->Divide(ndetectors, 1); particle_canvases.push_back(c); } /* iterate through energy levels, detectors, and particles and create plots for each */ for (int e = 0; e < nenergy_levels; ++e) for (int d = 0; d < ndetectors; ++d) for (int p = 0; p < nparticles; ++p) { /* +1 to account for 1-based indexing */ particle_canvases[p]->cd(d + 1); TH1F *const h = (TH1F *) h_base->Clone(); h->SetLineColor(plot_colors[e]); draw_histogram(h, particles[p], energy_levels[e], detectors[d]); } /* add legends */ for (int d = 0; d < ndetectors; ++d) for (int p = 0; p < nparticles; ++p) { particle_canvases[p]->cd(d + 1); gPad->RedrawAxis(); if (d == 0) { TLegend *const l = new TLegend(0.60, .90, .9, 0.625, generate_legend_header(particles [p], detectors [d])); l->SetTextSize(0.05); for (int e = 0; e < nenergy_levels; ++e) l->AddEntry(generate_histogram_name (particles[p], energy_levels[e], detectors[d]), generate_legend_entry_label (energy_levels[e]), "l"); l->Draw(); } else { TLegend *const l = new TLegend(0.60, .90, .9, 0.85, generate_legend_header(particles [p], detectors [d])); l->SetTextSize(0.05); l->Draw(); } gPad->SetLogy(); } /* save canvases to PNG */ for (int p = 0; p < nparticles; ++p) { TImage *const img = TImage::Create(); img->FromPad(particle_canvases[p]); char *const path = generate_save_file_path(particles[p]); img->WriteImage(path); delete img; } }
ENTRYPOINT void draw_bit (ModeInfo *mi) { bit_configuration *bp = &bps[MI_SCREEN(mi)]; Display *dpy = MI_DISPLAY(mi); Window window = MI_WINDOW(mi); int wire = MI_IS_WIREFRAME(mi); if (!bp->glx_context) return; glXMakeCurrent(MI_DISPLAY(mi), MI_WINDOW(mi), *(bp->glx_context)); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); if (!wire) { GLfloat pos[4] = {1.0, 1.0, 1.0, 0.0}; GLfloat amb[4] = {0.0, 0.0, 0.0, 1.0}; GLfloat dif[4] = {1.0, 1.0, 1.0, 1.0}; GLfloat spc[4] = {0.0, 1.0, 1.0, 1.0}; glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glLightfv(GL_LIGHT0, GL_POSITION, pos); glLightfv(GL_LIGHT0, GL_AMBIENT, amb); glLightfv(GL_LIGHT0, GL_DIFFUSE, dif); glLightfv(GL_LIGHT0, GL_SPECULAR, spc); } glPushMatrix (); glRotatef(current_device_rotation(), 0, 0, 1); glScalef(1.1, 1.1, 1.1); { double x, y, z; get_position (bp->rot, &x, &y, &z, !bp->button_down_p); glTranslatef((x - 0.5) * 11, (y - 0.5) * 5, (z - 0.5) * 3); gltrackball_rotate (bp->trackball); get_rotation (bp->rot, &x, &y, &z, !bp->button_down_p); glRotatef (x * 360, 1.0, 0.0, 0.0); glRotatef (y * 360, 0.0, 1.0, 0.0); glRotatef (z * 360, 0.0, 0.0, 1.0); } mi->polygon_count = 0; glScalef (6, 6, 6); { int nmodel = bp->history [bp->history_fp]; int omodel = bp->history [bp->history_fp > 0 ? bp->history_fp-1 : countof(bp->history)-1]; double now = double_time(); double ratio = 1 - ((bp->last_time + bp->frequency) - now) / bp->frequency; if (ratio > 1) ratio = 1; mi->polygon_count += draw_histogram (mi, ratio); mi->polygon_count += animate_bits (mi, omodel, nmodel, ratio); tick_bit (mi, now); } glPopMatrix (); if (mi->fps_p) do_fps (mi); glFinish(); glXSwapBuffers(dpy, window); }