C/C++ :: Convert 256 Color BMP Image To TXT File Of Array Of 0 - 255

Feb 5, 2015

I am working on a program which turns a 256 color bmp image to a txt file of a array of 0-255. I wrote this:

#include<iostream>
#include<fstream>
// if 1 , see bmp file header info
#if 1
#define SEE_INFO
#endif
using namespace std;

[Code] ....

Something weird happened. When I use it on simple.bmp (Attachment), it works fine. But when I use it on flower.bmp , it just give me zeros.

Attached File(s)

 simple.bmp (3.39K)
 simple.txt (8.47K)
 flower.bmp (76.05K)
 flower.txt (150.49K)

View 3 Replies


ADVERTISEMENT

C++ :: PPM Image File Magic Number And Max Color Value

Feb 28, 2015

When reading a PPM Image file, how would I find the magic number and the max color value?

int main() {
string imageFileName;
ifstream image;

imageFileName = "C:UsersDesktopdrink.ppm";
image.open(imageFileName.c_str(), ifstream::binary);

[Code] ....

The code gives me seemingly logical integer values for size, width and height. But how would I find the max color value and so called "magic number" for this PPM image file?

View 1 Replies View Related

Visual C++ :: How To Convert PNG Image Into Byte Array

Mar 12, 2013

I m loading a png image by using the ATLImage library.

CImage Image;
Image.Load (L"D:ImagesPNG_ImagesImage7.png");

how to retrieve the byte array value of this png image. I tried retrieving it as

byte *png = reinterpret_cast<BYTE *>(Image.GetBits());

but when i access the data , der is a loss of data while converting it in the above manner.

I found a snippet in net for decoding the raw data . but der is a line is the code which is unknown to me. The code is as follows :

CImage atlImage;
HMODULE hMod = GetModuleHandle(NULL);
atlImage.Load(bstr);
void* pPixel = atlImage.GetBits();
intpitch = atlImage.GetPitch();
intdepth = atlImage.GetBPP();

[Code] ....

How do I get the byte * value form the png image loaded?

View 3 Replies View Related

C++ :: Convert File (Audio / Image / Video) To Base64?

Sep 7, 2014

I'm looking to convert audio, images, video to base64 in c++, and through many searches on the web I've only seem to come up with string > base64.

When I view a .mp3 file for example, there are many characters there that are not available to be used in my string to encode.

[URL] ....

I have this code set up in my project, and all I want is to be able to give the location of any file and have it encode (could just encode to a string, I can handle writing it to a file), and then give a location to put the decoded file as well.

I'm not sure exactly where to even start.

View 6 Replies View Related

Visual C++ :: Placing Image In Kinect Color Frame?

Dec 10, 2012

I m trying to place an image on the colour frame of the Kinect live video. I m able to overlay the image using alpha blending mechanism.

The image used is a bitmap image of dimension 128*128.

The Kinect has a resolution of 640*480.

IDE used is Visual studio 2010 and I m developing using c++.

The Kinect has a render target whose size is taken as 640*480 so that it stretches for the complete window. So when I try to overlay the image it appears 5 times because of this stretching.
If I increase the image size to 640*128 i get a single image that is stretched horizontally across the window with dimension 640*480.

I have created a function that will create a render target with bitmap properties and size equal to 640*480. This is used to store the data from the Kinect, frame by frame, and draw it on to the screen

So I think when I overlay the image, it gets replicated 5 times to meet the render target size.By default the image is placed at the left top position.

My doubts are

- How can I use different functions to specify the size of render target for Kinect as 640*480 and the size of render target for bitmap image as 128*128.

- How to I give overlay or place the image on the live video at a specific location.

View 2 Replies View Related

C :: Blurring PPM Image By Averaging Components Of Color Within Certain Reach Of Specific Pixel

Mar 13, 2014

I'm trying to blur a ppm image by averaging the components of the color(r, g, b) within a certain reach of a specific pixel. This is a picture and description:

In this diagram, we are trying to compute the color for the pixel in the center (the red element). Its neighbors (within a reach of 4) are all of the green elements. The pixels outside of this 9x9 square are not considered in the blurring calculation for this pixel. To compute the color for the center pixel, average the red, green, and blue components (independently) of every pixel in the 9x9 square (including the pixel itself; the red element in this diagram).

I have some code, but it is not working correctly. The function "computed_color" on line 52 is shown in the next block of code.

Code:
#include <stdlib.h>
#include <stdio.h>
#include "blur_calculations.h"
#define NOT_ENOUGH_ARGS 2
#define MIN_ARGS 3
#define PICTURE_FILE 1
#define REACH_NUMBER 4
#define OUTPUT_FILE "blurred.ppm"
#define PPM_NUMBER "P3"
#define MAX_ROWS 500
#define MAX_COLS 500

void solve(FILE *in_picture, FILE *out_picture, char *argv[]) {

[Code] ....

Here is my code to calculate the average, which I use in my "solve" function:

Code:
#include "blur_calculations.h"
struct color create_color(int r, int g, int b) {
struct color colors;
colors.r = r;
colors.g = g;
colors.b = b;
return colors;

[Code] ....

View 4 Replies View Related

Visual C++ :: Convert HSB Color To RGB And RGB To HSB?

Jun 11, 2014

I am trying to make this code working and to remake it to work also for RGB to HSB? This code is for C and I need to make it working in Visual Studio C++ .

Code:
// mask1.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <stdio.h>
#include <math.h>
typedef struct RGB_t { unsigned char red, green, blue; } RGB;
typedef struct HSB_t { float hue, saturation, brightness; } HSB;

[code]....

Error I got is error C3861: 'fmaxf': identifier not found

What file or namespace should I include. Do I need to add some library into linker?

View 14 Replies View Related

C++ :: Convert Image To Number

May 15, 2013

I want to convert image to number.

View 12 Replies View Related

C/C++ :: Enable User To Upload Image And Convert It Into ASCII Text Using SDL

Apr 29, 2015

Using C . I have been tasked (for a University assignment) to create a program that will enable a user to upload an image and convert that image into ASCII text using SDL on a Linux system. I've managed to open a window, display an image (non-selected) and convert it into grayscale using

case SDLK_g:
for (int y = 0; y < image->h; y++) {
for (int x = 0; x < image->w; x++) {
Uint32 pixel = pixels[y * image->w + x];
Uint8 r = pixel >> 16 & 0xFF;
Uint8 g = pixel >> 8 & 0xFF;
Uint8 b = pixel & 0xFF;
Uint8 v = (0.212671*r)+(0.715160*g)+(0.072169*B)/>;
pixel = (0xFF << 24) | (v << 16) | (v << 8) | v;
pixels[y * image->w + x] = pixel;

I am absolutely clueless as to how I can get the user to upload an image to the program and then begin the image -> ASCII conversion. I've found seem to be written in C++ or C# to make the conversion I should be using the GetPixelColour command?

View 14 Replies View Related

Visual C++ :: Convert Floating Point Bilinear Image Resampling Routine?

Feb 19, 2013

In short I'm converting a floating point bilinear image resampling routine into one that only uses fixed point arithmetic. I've gotten rid of nearly all the floats now, in fact all but one and the results at the moment are in distinguishable from the floating point version. It's a maths issue really. Some pseudocode goes like this.

Code:
for( int xx=0; xx<ow; xx++ ) {
int_center = (ccx >> 16);
int temp = xx * 2;
for (j = int_center; j <= int_center + 1; j++)

[Code] ....

Where ccx is and integer error accumulator that gives me a scaled integer. Shifting down buy 16 gives me the relative pixel I need to be working on. The line just after where the inner loop begins is where I have the last remaining float. FILTER_FACTOR is essentially a percentage by which I scale the error accumulator to the correct amount.

For example.

ccx = 98303. Which is a value of 1.5 when shited down by 16 bits. Obviously I can shift it because it will round and I lose the precision. Lets say FILTER_FACTOR is 39321. Which is 60% of 1 (65535) So what I'd like to know is, is it possible to use the FILTER_FACTOR as an integer and do some fancy integer math to scale the result from (ccx - (j<<16)) by the representative amount that is FILTER_FACTOR. In this example 60%. Effectively getting 40% of (ccx - (j<<16)) At the moment FILTER_FACTOR is still a float and therefore 0.6, which of course works just fine.

View 4 Replies View Related

C# :: WPF Using Color Resource In Rectangle Stroke Color

Sep 7, 2014

Trying to define some global colors so I can use the one instance though-out my application. Here is my color code:

<Color x:Key="GlobalTextColor">#E0E0E0</Color>

But this color doesn't display in the list when I start to type {StaticResource ...}

This is the code where I'm trying to reference the color, see Stroke="{StaticResource GlobalTextColor}". GlobalTextColor doesn't actually come up in the list so won't work.

<Style x:Key="InputButton" TargetType="Button">
<Setter Property="Background" Value="#FF141414" />
<Setter Property="HorizontalAlignment" Value="Left" />

[Code].....

View 2 Replies View Related

C++ :: Selecting Random Color From Array

Jul 14, 2014

I have to write a program that selects a random color from an array. I used the srand (time(0)); statement but it still gives me the same color each time. Here is my code.

// Color.cpp
#include <ctime>
#include <iostream>
using namespace std;
#include <string>
#include <cstdlib>
#include "Color.h"

[Code] .....

View 7 Replies View Related

C++ :: Two Dimensional Array - Resistor Color Band

Nov 15, 2013

Using functional decomposition, write a C++ program that will prompt user for the all the color bands of a resistor and then calculate the value of the resistor.

The first 3 bands are digits, the 4th is power of 10X and 5th is tolerance.

Here is what the picture look similar to : [URL] ....

if 1st is green (value 5)
2nd is blue (value 6)
3rd is black (value 0)
4th is orange (value 3)
5th is silver (10%)
resistor is 560 x 10^3 with 10% tolerance. or 560 Kilo-ohm with 10% tolerance

a sample program out put:

char BAND_COLOR_CODE[10][8] = {“black”,”brown”,”red”,”orange”,
“yellow”,”green”,”blue”,”violet”,
“grey”,”white”};

[Code] ....

View 1 Replies View Related

C++ :: Initialize Size Of Vector Array Position And Color?

Feb 3, 2015

Getting back into programming after a few years off and a bit rusty.

My question is: Is this going to initialize the size of the vector array's position and color properly?

#include <GLFW/glfw3.h>
#include <vector>
class TerrainClass {
private:
struct VertexType {
std::vector<float> position[3];

[Code]...

View 6 Replies View Related

C :: Read A 24 Bit Image Using 2D Array

Oct 29, 2013

I am trying to read a 24 bit image but I'm getting errors when I'm tryting to read the pixels.

-The reading part looks bad because I'm reading both headers field by field. But I'm sure that it is reading both headers correctly.

-Right now my biggest concern is to get it to read successfully an entire bmp image

I'm using this calculation to get my padding bytes:

padding bytes = [4-(3*width)mod 4]mod 4

When I use a 2x2.bmp file to test it, I get an error that the [1][1] pixel was not read. When I use a bigger image it gives me the same error after about 100 rows and then every pixel is an error from that point on. This is what I got so far:

Code:

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
const size_t cSizeofPixel = 3; //size of struct tPixel
typedef struct{
unsigned char blue;
unsigned char green;
unsigned char red;

[Code]...

I read this post Reading 24 bit BMP file into a 2d array.

I still don't know if my error is when I allocate memory to my 2d array, or if I'm doing the padding bytes wrong or if it is something else.

View 8 Replies View Related

C :: Reading PPM Image Into 1D Or 2D Array

Apr 4, 2013

I have an assignment where I need to take an assigned image, rotate it 90 degrees to the right, flip it upside down, and turn it to grayscale; each with different outputs.

I was thinking if I can read in the image into a 2d array //array[height][width] or even just an array with the values of each pixel (r, g, b), I can just modify the array and spit it out when done.

if i can just get it into the array, I think I'll be fine. We've done similar assignments with modifying arrays for grayscale images and the other two I can probably figure out. But how am I going to read in each pixel into an array with three different values in each slot? This is my code so far:

Code:
#include<stdio.h>

View 1 Replies View Related

C++ :: Use 3D Array To Create Image

Sep 16, 2014

My assignment is use a 3D array to create an image. Use an array of the form arr[300][200][3]. For this homework, you need to use an array of the form arr[3][400][500]. It will have 400 rows and 500 columns. You need to first initialize the array as described in class and after that write the array to a ppm image file. When viewed using Gimp, it should display USM. The letters would be 200 pixels high and 100 pixels wide each. Use at least 15 pixels for the width of the stroke. Use different colors for each letter and a different color for the background.This is what I have so far.

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

void initialize(unsigned char a[][200][3], int nrows, int ncols, int nc);
void printAll(unsigned char a[][200][3], int nrows, int ncols, int nc);

[code]....

View 3 Replies View Related

C# :: Compare The Image Of A Button To Another Image In Visual Studio

Jul 3, 2014

Im trying to compare the image of a button to another image in Visual Studio like so...

//variables
Image active = Image.FromFile("C:\Users\Ethan\Desktop\StarWars Status\active.png");
Image stunned = Image.FromFile("C:\Users\Ethan\Desktop\StarWars Status\stunned.png");

[Code]...

btnStatusPlr1.Image SHOULD come back as True.Then I realized it might not be the same as setting the buttons image in the properties (Which is what i did to get the original image (the one being compared to))

I do have a feeling ive done something wrong here (Yes im a noob /> )

Variable active, is the same image as the buttons default (Well should be)

View 1 Replies View Related

C++ :: Run Image (GIF File) Through CMD

Apr 6, 2014

I would like to know if it possible to "run" an image through CMD.In other words i want that image to be opened on CMD.

BTW the image which i am more intrested is GIF files.

View 3 Replies View Related

C :: Reading PPM Image Into 2 Dimensional Array

Nov 29, 2014

I'm trying to read a PPM image into an array. The header will have already been read in and I'm trying to put in a 2-d array to make manipulations easier. This is the code I have so far with LOTS of errors and warnings and I honestly don't know what almost any of them mean.

Code:

int imageArray( FILE *input, struct pixel *theArray ){
int i, j;
int col, row;
int *imageArray = (int**)malloc(row * sizeof(int*));
for(i=0; i<row; i++){

[Code]...

View 3 Replies View Related

C++ :: Transform Integer Array To BMP Image

Jun 8, 2013

I have a problem concerning transforming int array into bmp image. I wanted to add a post in this topic: [URL] .... , but unfortunately it is closed. Actually I have a question concerning the code written by Duoas. I have a function which takes values from the file and I want to convert it into bmp with the use of Duoas code. I do it like that(it's Duoas code + my load and main function) Is it something wrong with how I do it or it's rather sth wrong with the file.

It compiles without errors but when I run it: core dumped.

According to gdb debugger problem is here: double hue = (intarray[ row - 1 ][ col ] - min_value) * granularity; programs stops, segmentation fault ...

#ifndef INTARRAY2BMP_HPP
#define INTARRAY2BMP_HPP
#include <fstream>
#include <iostream>
#include <string>

[Code] ....

View 2 Replies View Related

C++ :: Propagation Algorithm - Image To 2D Array

Feb 17, 2015

A few months ago I wrote a simple neural network using back propagation algorithm. It's input is a 2D array of any given size and type. I tried to make it learn the logic functions like AND & OR it worked. So now I want to try image recognition and I need the image as a 2D array of RGB values.(I mean three arrays of course one 2D array for each color.)

How can I get an array of RGB from an image? Can I do it with streams?

View 1 Replies View Related

C++ :: Retrieve The Image From URL And Save It In Array?

Sep 10, 2013

I am trying to retrieve an image from its URL as an array where each box represents the pixel value of the image.

View 3 Replies View Related

C/C++ :: How To Print PPM Image From A File

Apr 6, 2015

I have an assignment to manipulate a ppm image which I'm having a lot of difficulty with and I have to have a function to print the ppm but I dont know how to send the ppm file to said function for printing.

#include "transform.h"
int print(void){
int i;
printf("P6
");
printf("%d %d
", g_width, g_height);
printf("22
");
}

View 12 Replies View Related

C/C++ :: Reading Image From A File?

Sep 30, 2013

How to read an image in C++ ...

All what i know that i may use a Cimage library but it doesn't really work or to read the image from a file ....

View 4 Replies View Related

C++ :: Program To Read Image (Later Represent By Array 3D)

May 1, 2013

I will make a program to read the image in C++. And later, the image will represent by array 3D, which (x,y) represent the spatial coordinate of (height*weight) image (pixel) and z represent the intesity of those image (0-255).

In matlab, the code for do that is --> imread('image.jpg')

How can I do that in C++?

View 2 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved