pixels

C++, Negative RGB values of pixels using OpenCV

本小妞迷上赌 提交于 2019-11-30 15:48:42
I'm using OpenCV to iterate through an image and find the colour of each pixel, here's some of the code I'm using: IplImage* img = cvLoadImage("c:\\test.png"); int pixels = img->height * img->width; int channels = img->nChannels; for (int i = 0; i < pixels*channels; i+= channels) { unsigned char red = img->imageData[i + 2]; unsigned char green = img->imageData[i + 1]; unsigned char blue = img->imageData[i]; outputRGBValues(red, green, blue); if (red == REDCOLOUR && green == GREENCOLOUR && blue == BLUECOLOUR) { count++; } } cvReleaseImage(&img); When I run it, it outputRGBValues outputs

Highlight differences between images

◇◆丶佛笑我妖孽 提交于 2019-11-30 14:06:55
There is this image comparison code I am supposed to modify to highlight/point out the difference between two images. Is there a way to modify this code so as to highlight the differences in images. If not any suggestion on how to go about it would be greatly appreciated. int width1 = img1.getWidth(null); int width2 = img2.getWidth(null); int height1 = img1.getHeight(null); int height2 = img2.getHeight(null); if ((width1 != width2) || (height1 != height2)) { System.err.println("Error: Images dimensions mismatch"); System.exit(1); } long diff = 0; for (int i = 0; i < height1; i++) { for (int j

Convert Pixels to Inches and vice versa in C#

我与影子孤独终老i 提交于 2019-11-30 13:47:58
I am looking to convert pixes to inches and vice versa. I understand that I need DPI, but I am not sure how to get this information (e.g. I don't have the Graphics object, so that's not an option). Is there a way? On a video device, any answer to this question is typically not very accurate. The easiest example to use to see why this is the case is a projector. The output resolution is, say, 1024x768, but the DPI varies by how far away the screen is from the projector apeture. WPF, for example, always assumes 96 DPI on a video device. Presuming you still need an answer, regardless of the

How to convert DLU into pixels?

浪尽此生 提交于 2019-11-30 13:21:25
问题 Microsoft uses dialog length units (DLU) in their guidelines for UI. How can I convert them into pixels? As I know, DLU depending on system font size. Can you advise some simple method of such conversion in Delphi for Win32? 回答1: You should use the MapDialogRect() function. Pass in a RECT in dialog units, and the equivalent RECT in pixel units is returned. Note that you need a handle to a dialog in order to give MapDialogRect() sufficient context. The function needs to know the font in order

How to get matplotlib figure size

会有一股神秘感。 提交于 2019-11-30 12:29:26
问题 For a project, I need to know the current size (in pixels) of my matplotlib figure, but I can't find how to do this. Does anyone know how to do this ? Thanks, Tristan 回答1: import matplotlib.plt fig = plt.figure() size = fig.get_size_inches()*fig.dpi # size in pixels To do it for the current figure, fig = plt.gcf() size = fig.get_size_inches()*fig.dpi # size in pixels You can get the same info by doing: bbox = fig.get_window_extent().transformed(fig.dpi_scale_trans.inverted()) width, height =

Converting an array of Pixels to an image in C#

喜你入骨 提交于 2019-11-30 12:21:00
问题 I have an array of int pixels in my C# program and I want to convert it into an image. The problem is I am converting Java source code for a program into equivalent C# code. In java the line reads which displays the array of int pixels into image: Image output = createImage(new MemoryImageSource(width, height, orig, 0, width)); can someone tell me the C# equivalent? Here orig is the array of int pixels. I searched the Bitmap class and there is a method called SetPixel but the problem is it

Create a buffered image from rgb pixel values

折月煮酒 提交于 2019-11-30 09:55:37
I have an integer array of RGB pixels that looks something like: pixels[0] = <rgb-value of pixel(0,0)> pixels[1] = <rgb-value of pixel(1,0)> pixels[2] = <rgb-value of pixel(2,0)> pixels[3] = <rgb-value of pixel(0,1)> ...etc... And I'm trying to create a BufferedImage from it. I tried the following: BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); img.getRaster().setPixels(0, 0, width, height, pixels); But the resulting image has problems with the color bands. The image is unclear and there are diagonal and horizontal lines through it. What is the proper way to

How to get matplotlib figure size

混江龙づ霸主 提交于 2019-11-30 05:43:01
For a project, I need to know the current size (in pixels) of my matplotlib figure, but I can't find how to do this. Does anyone know how to do this ? Thanks, Tristan import matplotlib.plt fig = plt.figure() size = fig.get_size_inches()*fig.dpi # size in pixels To do it for the current figure, fig = plt.gcf() size = fig.get_size_inches()*fig.dpi # size in pixels You can get the same info by doing: bbox = fig.get_window_extent().transformed(fig.dpi_scale_trans.inverted()) width, height = bbox.width*fig.dpi, bbox.height*fig.dpi 来源: https://stackoverflow.com/questions/29702424/how-to-get

Efficient pixel shader sum of all pixels

£可爱£侵袭症+ 提交于 2019-11-30 04:17:42
问题 How can I efficiently calculate the sum of all pixels in an image, by using a HSLS pixel shader? I'm interested in Pixel Shader 2.0, that I could invoke as a WPF shader effect. 回答1: There is a much simpler solution that doesn't use shaders: load the image as a texture, create a mipmap chain and read back the value of the last mipmap (1x1 pixel). This trick is used in games extensively to calculate, for example, the average brigthness of a scene (in order to apply HDR tonemapping). It's a

How do dp, dip, dpi, ppi, pixels and inches relate?

一曲冷凌霜 提交于 2019-11-30 03:00:57
I was reading dp, dip, px, sp measurements , but I still have some questions about dp/dpi vs ppi vs px vs inch. I am not able to compare them... is an inch the largest? They say 160 dpi means 160 pixels per one inch. Does that mean 1 inch contains 160 pixels? They also say 1 pixel on a 160 dpi screen = 1 dp. Does that mean 1 pixel and 1 dp are equal? And lastly, why should we use dp instead of px? I understand that it is ideal, but why ? You should (almost) always use flexible sizing units, like dp , which is Density-Independent Pixels, because 300px on one device is not necessarily the same