converting rgb image to gray image in vc++ using opencv - visual-c++

i created gui application in vc++2010 express, i loaded image folder to list box and by selecting listbox item the image is displaying in picturebox1, using browse button.
Now i want to access the picturebox1 image and convert to gray scale image and converted grey scale must be displayed in picturebox2, using grey convert button. plzz help me frnds
thanq
karuna

Get the image in opencv Mat. Then use cvtColor function to convert the image. CV_BGR2GRAY code is used to convert from RGB to grayscale. Then show the grayscale image back to wherever you want to display it.

Related

Issue with color profile of CMYK image

The issue
I'm chasing a color issue that occurs during a gm convert of a jpg in CMYK colorspace to png. Just when I thought I'd isolated the issue and wanted to upload the images I realized that my issue has none to do with GraphicsMagick as the upload preview already showed the issue on the source image.
The source image
The majority of image tools (including XnView, browser) renders it light green.
Some image tools (including Faststone Image Viewer) render this image with dark green color:
To persist the issue
Running gm convert isolated-in.jpg png:isolated-out.png persists this light green for all image renderes.
The desired outcome
The dark green color is the desired outcome. I understand that there must be a corruption of the color profile of the input image. Infact, there seems to be none. However, some image tools render it correctly, making me beliefe there is a differet "guess" on the profile. What are those image tools doing so that it appears dark green? And, can I, with gm identify and/or gm convert correct for the missing/corrupted color profile of the source and persist the correct color, which is dark green?

Why is a generated SVG image less rich than the corresponding PNG image

To set this up, I used svgwrite library to create a sample SVG image (20 squares of length 100 at random locations on a display size of length 400)
import svgwrite
import random
random.seed(42)
dwg = svgwrite.Drawing('x.svg', size=(400,400))
dwg.add(dwg.rect(insert=(0,0), size=('100%', '100%'), fill='white')) # White background
for i in range(20):
coordinates = (random.randint(0,399), random.randint(0,399))
color = (random.randint(0,255), random.randint(0,255), random.randint(0,255))
dwg.add(dwg.rect(coordinates, (100, 100),
stroke='black',
fill=svgwrite.rgb(*color),
stroke_width=1)
)
dwg.save()
I then wrote a sample pygame program to generate a PNG image of the same sample. (A seed has been used to generate the same sequence of squares.)
import pygame
import random
random.seed(42)
display = pygame.display.set_mode((400,400))
display.fill((255,255,255)) # White background
for i in range(20):
coordinates = (random.randint(0,399), random.randint(0,399))
color = (random.randint(0,255), random.randint(0,255), random.randint(0,255))
pygame.draw.rect(display, color, coordinates+(100,100), 0)
pygame.draw.rect(display, (0,0,0), coordinates+(100,100), 1) #For black border
pygame.image.save(display, "x.png")
These are the images that I got (SVG's can't be uploaded to SO, so I have provided a screenshot. Nevertheless, the programs above can be run to output the same).
My question is, why is the PNG (on the left) richer and sharper than the corresponding SVG image? The SVG looks blurred and bland, comparatively.
EDIT: One can notice the fine white line between the first two squares at the top-left corner. It's not very clear in the SVG.
Two things I think may impact:
You are using an image viewer, which could distort the vectorial SVG image. I think all of the vector images viewers get the actual screen size, then export the vectorial image into a matrix image sized in function of the size of the screen you have. Then they display the matrix image. If they render the image with softened sharpness, or if they have a problem by getting the size of your screen, the image may be blurred.
To make the PNG image, you use pygame. But you are using another module to make the SVG image. This module may function differently, and also exports the image with another quality than if you were exporting it with pygame.
For me personally the SVG image appears blurred with Gimp, for example, but not with another SVG viewer.
So I think the problem comes from your image viewer.

How to extract background image and text from a image

I have an image and am trying to separate the background image and text.
For text I have used pytesseract and it gives me all the data. Now my aim is to translate this text and place it back on the image.
For that I need the background image and the position of the text where I need to put the text back.
I need some help or pointers as I have been trying to use OpenCV for same but no luck yet.
Thanks
-Megha

How to change a part of the color of the background, which is black, to white?

I have been working on PyTesseract OCR and converting PDF to JPEG inorder to OCR the image. A part of the image has a black background and white text, which Tesseract is unable to identify, whereas all other parts of my image are being read perfectly well. Is there a way to change a part of the image that has black background? I tried a few SO resources, but doesn't seem to help.
I am using Python 3, Open CV version 4 and PyTesseract
opencv has a bitwise not function wich correctly reverses the image
you can put a mask / freeze on the rest of the image (the part that is correct already) and use something like this:
imageWithMask = cv2.bitwise_not(imageWithMask)
alternatively you can also perform the operation on a copy of the image and only copy over parts / pixels / regions you need....

How to save as PNG to tkinter's Image(Penguin)

IMAGE
when I click file>>save as png...
It will save as png to that penguin. Is it possible?
It is possible but the image must be a tkinter PhotoImage.
The picture of your program suggests that it's not a photoimage. However; google "tkinter PhotoImage" and you will find information on how to build one pixel by pixel or however you want. Once you have a photoimage, saving it is easy:
image.write('some_name.png', format='png')

Resources