This question already has an answer here:
How to get a binding point of an image variable in OpenGLES
(1 answer)
Closed 7 years ago.
Is there a function to get the currently bound image texture?
I can get the currently bound texture for glBindTexture with glGetIntegerv(GL_TEXTURE_BINDING_2D, &bound_texture);.
Does something similar exist for glBindImageTexture?
ยง 8.26.1 Image Unit Queries
The state required for each image unit is summarized in table 23.45 and may be
queried using the indexed query commands in that table. The initial values of
image unit state are described above for BindImageTexture.
The enum you probably want is GL_IMAGE_BINDING_NAME.
Related
This question already has an answer here:
How to display resulting image of mainwindow in another window in C++ and QT?
(1 answer)
Closed 3 years ago.
I'm trying to show a disparity map with stereoSGBM from opencv, but when I show the map, 3 images appear, and I can't find how to show only one disparity map. Here an exemple of what appears (I display it whit the QPixmap class):
Here is my code :
cv::Ptr<cv::StereoSGBM> sgbm = cv::StereoSGBM::create(0, 16, 3);
cv::Mat cv_res;
sgbm->setMode(cv::StereoSGBM::MODE_SGBM_3WAY);
sgbm->compute(left, right, cv_res);
I had to convert the image to Indexed8.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
So I'm staring a project about image processing with C++.
The thing is that everything I find online about this matter (blurring an image in C++) comes either with CUDA or with OpenCV.
Is there a way to blur an image with C++ only? (for starters)
If yes, can somebody please share the code or explain?
Thanks!
Firstly you need the image in memory.
Then you need a second buffer to use as a workspace.
Then you need a filter. A common filter would be
1 4 1
4 -20 4
1 4 1
For each pixel, we apply the filter. So we're setting the image to a weighted average of the pixels around it, then subtracting to avoid the overall image going lighter or darker.
Applying a small filter is very simple.
for(y=0;y<height;y++)
for(x=0;x<width;x++)
{
total = image[(y+1)*width+x+1];
for(fy=0; fy < 3; fy++)
for(fx = 0; fx < 3; fx++)
total += image[(y+fy)*width+x+fx] * filter[fy*3+x];
output[(y+1)*width+x+1] = clamp(total, 0, 255);
}
You need to special case the edges, which is just fiddly but doesn't add any theoretical complexity.
When we use faster algorithms that the naive one it becomes important to set up edges correctly. You then do the calculations in the frequency domain and it's a lot faster with a big filter.
If you would like to implement the blurring on your own, you have to somehow store the image in memory. If you have a black and white image, an
unsigned char[width*height]
might be sufficient to store the image; if it is a colour image, perhaps you will have the same array, but three or four times the size (one for each colour channel and one for the so-called alpha-value which describes the opacity).
For the black and white case, you would have to sum up the neighbours of each pixel and calculate its average; this approach transfers to colour images by applying the operation to each colour channel.
The operation described above is a special case of the so-called kernel filter, which can also be used to implement different operations.
This question already has answers here:
OpenCV cv::Mat set if
(3 answers)
Closed 6 years ago.
I have calculated anomaly image from grayscale image. The result is in the image below:
anomaly image with 5 anomalies
once I got result above I want to colorize anomalies with:
1. red color, if the anomaly area is greater than 10 px or
2. green color, if the anomaly area is les than or equal to 10 px.
For calculating properties of anomalies I used opencv function ''connectedComponentsWithStats()''. I can see that function calculated for me centroids of anomalies and also areas..
How can I now color all detected connected components?? In matlab I was using comething like pixelIdList to address each connected component and repmat(1,1,3) to extend binary image to RGB and then set up one of the chanels to ''true'', but how can I address all connected components in c++ ??
You could do the same thing in OpenCV. Change the channels of your output image to 3 (RGB/BGR). Then you can loop through each pixel and set it to the colour you want based on their other criteria like (area, centroid) in a nested if loop.
This question already has answers here:
How do I generate an image from a matrix (with floating point entries)
(2 answers)
Closed 8 years ago.
1.I have matrix 180*200 of intensity values.
2.I want image which represent this intensity values.
I don't have MATLAB on this machine (or any of your input) so I can't test. But I think this is what you're looking for
http://www.mathworks.com/help/images/ref/mat2gray.html
(Google is your friend)
The relevant code to you is:
I = mat2gray(A)
where A is the matrix containing your information
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I know there is a question about this already but it does not give a solution in code.
I'm trying to load a bitmap image into a GL application using this function:
void glBitmap(GLsizei width,
GLsizei height,
GLfloat xorig,
GLfloat yorig,
GLfloat xmove,
GLfloat ymove,
const GLubyte * bitmap);
Can someone give me a function that returns a GLubyte* given a filename? I've been looking all over the web for a working algorithm but can't seem to get any to work.
The problem with using glBitmap to display the image is that you need to load the image from a file, and then interpret the data as colour index array. Since every possible library and example interpret the image data as RGB (or RGBA), and since color table needs to be set using glColorTable, nobody is using glBitmap to load the image, therefore there are no real examples of how to use glBitmap with data loaded from the file.
By the way, this is from glBitmap reference page :
The bitmap image is interpreted like image data for the glDrawPixels
command, with width and height corresponding to the width and height
arguments of that command, and with type set to GL_BITMAP and format
set to GL_COLOR_INDEX.
Save yourself trouble, and use glDrawPixels or textures to display the image from a file.
This page contains the example how to display the image using glBitmap, but not from the file.
First you need to understand what glBitmap does: glBitmap is a drawing function. It looks at each bit (hence bit map) of the given data, interpreted as a 2 dimensional array and relative to the current raster position (set with glRasterPos) sets those pixels to the currently set raster color (glRasterColor) whose corresponding bit in the bitmap are set. Each GLubyte contains 8 bits, so each byte covers 8 pixels width (endianess is set using glPixelStore).
A for reading a bitmap from a file. AFAIK there's only one widespread bitmap format (in contrast to pixmaps which have channels, where each pixel's channel can assume a range of values). That format is PBM: http://en.wikipedia.org/wiki/Netpbm_format
Given the information from the Wikipedia page it is straightforward to write a function that opens and reads a PBM file (functions required are fopen, fread and fclose) into a structure holding the data. Then one can use that structure to feed the data to glBitmap.
But remember, bitmaps are just binary valued images, i.e. black and white, no grays, not to speak of colour.
Now your notion was "loading a bitmap". I already told, that glBitmap immediately draws the data you give it. So I think what you're actually looking for is textures and a image file to texture loader.