| | |
Image read and operation on it
![]() |
So you have pixels represented as some number of shades of gray. And you want to AND them with something? Why AND? Is this some sort of mask where all ON (black? white?) is a mask to include the pixel and OFF is a mask to not include. In that case you could say:
but if the mask is not all ON or all OFF bits (0x0 or 0xFF, say) then the resulting pixels will not be a gray scale but some odd shade. Like, if the mask is 0x5A and you mask that with a gray representing 20% gray you get a strange gray.
C Syntax (Toggle Plain Text)
for each row, for each column, result = pixel[row][col] & mask[row][col]; // '&' being bitwise-and
•
•
Join Date: Nov 2004
Posts: 9
Reputation:
Solved Threads: 0
Its like i will be altering the image at variuos postions (on copies of the original image), and an AND operation is performed so that if it is a 1, then the particular pixel ahs not been altered. THe pixel will take values from 0 to 256 (8bits).
•
•
•
•
Originally Posted by Chainsaw
So you have pixels represented as some number of shades of gray. And you want to AND them with something? Why AND? Is this some sort of mask where all ON (black? white?) is a mask to include the pixel and OFF is a mask to not include. In that case you could say:
but if the mask is not all ON or all OFF bits (0x0 or 0xFF, say) then the resulting pixels will not be a gray scale but some odd shade. Like, if the mask is 0x5A and you mask that with a gray representing 20% gray you get a strange gray.C Syntax (Toggle Plain Text)
for each row, for each column, result = pixel[row][col] & mask[row][col]; // '&' being bitwise-and
You could just say....
if (mask_bit == 1)
result = original;
else
resilt = altered_pixel;
Becuase if the mask is one bit and the pixel is 8 bits you'd have to do some fussing with stuff to make AND work. If they are both 8 bits you could say:
result_pixel = mask_pixel & original_pixel;
but now the result is either 0 or original_pixel, you still have to supply the modified pixel.
Maybe some pseudocode or real code would help. What have you got so far?
if (mask_bit == 1)
result = original;
else
resilt = altered_pixel;
Becuase if the mask is one bit and the pixel is 8 bits you'd have to do some fussing with stuff to make AND work. If they are both 8 bits you could say:
result_pixel = mask_pixel & original_pixel;
but now the result is either 0 or original_pixel, you still have to supply the modified pixel.
Maybe some pseudocode or real code would help. What have you got so far?
•
•
Join Date: Nov 2004
Posts: 9
Reputation:
Solved Threads: 0
OK .. i may have not put the problem thru clearly. I have a 512X512 pixel image. On which i make say 5 copies and make slight variations on these 5 images.What i have to do is read each pixel say at [1,1] of each of these 5 images and do an AND operation of all 5. Pls note that the original is not being involved, and no comparison is being made to the original. What is possible is that the alteration could be the same in a particular pixel? But that doesnt matter, if the value of a particular pixel is same in all the images then i neeed the location of the pixel. And operation is one way of finding out, if by ANdin the particular pixel of all the images is 1 then i need the pixel location.
Sorry if i am bothering u, but if you could get me a rough code then it would be great, im not so well versed in C.
Thank you
j
Sorry if i am bothering u, but if you could get me a rough code then it would be great, im not so well versed in C.
Thank you
j
It's no bother at all, but you are right I don't understand what you are attempting. It sounds like you are doing something to these 5 copies and then seeing if doing something to them didn't change them. And it sounds like you are determined to use AND rather than ==, yet I don't get why.
Maybe it is time for someone else on this forum to chime in; I'm just being dense.
Maybe it is time for someone else on this forum to chime in; I'm just being dense.
•
•
Join Date: Oct 2004
Posts: 31
Reputation:
Solved Threads: 0
u can use this code;
you can then alter the values in image array to play with the image.
C Syntax (Toggle Plain Text)
#include<stdio.h> int main(void) { FILE *fp; unsigned char image[256][256]; int r,c; if((fp = fopen("f16.dat","r+")) == NULL) { printf("Unable to open the specified file.\n"); getch(); exit(1); } else { for(r=0;r<256;r++) { for(c=0;c<256;c++) { image[r][c]=(unsigned char) fgetc (fp); } } fclose(fp); } getch(); return(0); }
you can then alter the values in image array to play with the image.
•
•
Join Date: Nov 2004
Posts: 9
Reputation:
Solved Threads: 0
I wrote a code but the output file is not being written (image file), but when reading the array i am getting the bits for each pixel. Can u take a look at it?
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#define size 512
#define num_images 2
using namespace std;
int main() {
char *filename[num_images] = {"92eb.raw","92eb.raw"};
unsigned char Imagedata[2][size][size];
unsigned char outputData[size][size];
FILE *input, *output;
for (int i = 0; i < num_images; i++) {
if (!(input = fopen(filename[i],"rb"))) {
cout << "Unable to open file" <<endl;
return 0;
}
fread(Imagedata[i],sizeof(unsigned char),size * size,input);
}
int result = 1;
for (int j = 0; j < size; j++) {
for (int k = 0; k < size; k++) {
for (int i = 0; i < num_images; i++) {
result=result & Imagedata[i][j][k];
}
outputData[j][k] = result;
result = 1;
}
}
if (!(output = fopen("output.raw", "wb"))) {
cout << "Could not open file for writing" << endl;
}
int ret = fwrite(outputData,sizeof(unsigned char), size * size,output);
cout << "Number of items written" << ret << endl;
return 1;
}
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#define size 512
#define num_images 2
using namespace std;
int main() {
char *filename[num_images] = {"92eb.raw","92eb.raw"};
unsigned char Imagedata[2][size][size];
unsigned char outputData[size][size];
FILE *input, *output;
for (int i = 0; i < num_images; i++) {
if (!(input = fopen(filename[i],"rb"))) {
cout << "Unable to open file" <<endl;
return 0;
}
fread(Imagedata[i],sizeof(unsigned char),size * size,input);
}
int result = 1;
for (int j = 0; j < size; j++) {
for (int k = 0; k < size; k++) {
for (int i = 0; i < num_images; i++) {
result=result & Imagedata[i][j][k];
}
outputData[j][k] = result;
result = 1;
}
}
if (!(output = fopen("output.raw", "wb"))) {
cout << "Could not open file for writing" << endl;
}
int ret = fwrite(outputData,sizeof(unsigned char), size * size,output);
cout << "Number of items written" << ret << endl;
return 1;
}
![]() |
Similar Threads
Other Threads in the C Forum
- Previous Thread: graphics in c language
- Next Thread: more help on checkbook
| Thread Tools | Search this Thread |
* adobe api array arrays binarysearch calculate centimeter char cm convert copyanyfile copypdffile cprogramme createcopyoffile createprocess() csyntax directory dynamic feet fflush file floatingpointvalidation fork forloop frequency getlasterror getlogicaldrivestrin givemetehcodez global graphics gtkgcurlcompiling gtkwinlinux hacking hardware highest homework i/o ide inches incrementoperators intmain() iso km linked linkedlist linux linuxsegmentationfault list locate logical_drives loopinsideloop. match matrix microsoft motherboard mqqueue mysql oddnumber odf open opendocumentformat opensource openwebfoundation pattern pdf performance pointer posix power program programming pyramidusingturboccodes read recursion recv recvblocked repetition scanf scheduling segmentationfault send shape single socketprograming socketprogramming stack standard strchr string suggestions test unix urboc user variable voidmain() whythiscodecausesegmentationfault win32api windows.h





