Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed last month.
Improve this question
I am trying to convert an image into grayscale using python and cv2. I saw a few other answers and they were using matlab, which I am not going to use. Is there anyway that I can fix this issue. The image boots up fine and everything it just wont convert. Here is the code.
import cv2
# Choose an image to detect faces in
img = cv2.imread('RDJ.png')
# Must convert to grayscale
grayscaled_img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
#
cv2.imshow('Face Detector', img)
cv2.waitKey()
I have tried to fix it using different things but I cant figure out any solutions.
You need to change the penultimate line of your code:
cv2.imshow('Face Detector', grayscaled_img)
Because the image showed is the original.
Related
Closed. This question is not about programming or software development. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 5 days ago.
Improve this question
for my thesis I'm working on a classifier (with Tensorflow) able to classifier if a heart trace contains or not an aritmia.
But I have a problem with the dataset: Practically, this is one image of my dataset:
The problem is that if we zoom on the trace we can see this:
Practically the outline of the curve has some kind of gradient around it. Could someone tell me how to eliminate this nuance in Python and maybe, how to increase the thickness of the stroke in order to highlight it?
Thanks a lot to everybody
Update 1:
I'm trying with this code, that seem resolve the problem, but when I apply cv2.dilate the image appear complete white.
import numpy as np
import cv2
for file in os.listdir("data/clean_test/original"):
img = image.load_img("data/clean_test/original/" + file, color_mode="grayscale")
img = image.img_to_array(img, dtype="uint8")
# do OTSU threshold to get circuit image
thresh = cv2.adaptiveThreshold(
img, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY, 15, 100
)
kernel = np.ones((5, 5), np.uint8)
dilation = cv2.dilate(thresh, kernel, iterations=1)
print("Processed image: " + file)
cv2.imwrite(
"data/clean_test/new/" + os.path.splitext(file)[0] + ".png",
thresh,
[cv2.IMWRITE_PNG_COMPRESSION, 0],
)
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 2 years ago.
Improve this question
I am a naive Python coder so pardon my ignorance.
I wanted to know how does img = np.zeros((300,512,3), np.uint8) generate a black window in OpenCV. Also if someone could help me understand the importance of channels, in my case (300,512,3) '3' is the channel.
I tried googling it out and found https://answers.opencv.org/question/74576/how-does-npzeros-create-a-black-background/ but still am confused!.
Thanks in advance guys!!
The line
img = np.zeros((300,512,3), np.uint8)
creates a 3D array that is 300 rows high, 512 columns wide, and 3 "channels" deep. Each channel corresponds to the amount of red, green, or blue intensity.
np.zeros
means that this array will be completely filled with 0's.
0 intensity for red, green, and blue translates into a black image.
This type of encoding is called RGB, because each color channel represents the intensity of red, green, or blue.
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 2 years ago.
Improve this question
My problem is that I want to differentiate the light and dark areas in the following image to generate a binary mask.
https://i.stack.imgur.com/7ZRKB.jpg
An approximation to the output can be this:
https://i.stack.imgur.com/2UuJb.jpg
I've tried a lot of things but the results still have some noise or I lost a lot of data, like in this image:
https://i.stack.imgur.com/hUyjY.png
I've used python with opencv and numpy, gaussian filters, opening, closing, etc...
Somebody have some idea to doing this?
Thanks in advance!
I first reduced the size of the image using pyrDown then used CLAHE to equalize the histogram. I used medianblur as this will create patches then used opening 3 times. After that it was a simple binary_inv threshold. If you want to get the original image size, use cv2.pyrUp on image. By playing with the parameters you can manage to get better results.
import cv2
image = cv2.imread("7ZRKB.jpg",0)
image = cv2.pyrDown(image)
clahe = cv2.createCLAHE(clipLimit=2.0, tileGridSize=(16,16))
image = clahe.apply(image)
image = cv2.medianBlur(image, 7)
kernel = cv2.getStructuringElement(cv2.MORPH_RECT,(5,5))
image = cv2.morphologyEx(image, cv2.MORPH_OPEN, kernel, iterations=3)
ret,image = cv2.threshold(image, 150, 255, cv2.THRESH_BINARY_INV)
cv2.imshow("image",image)
cv2.waitKey()
cv2.destroyAllWindows()
Result:
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I would like compare a frame of video with another image but i don't know how can i do it with python.
Someone can help me please
You can use various metrics, look them up to see how they're calculated and when you should use them. In Python this can be achieved easily with scikit-image.
import cv2
from skimage.measure import compare_mse, compare_nrmse, compare_ssim, compare_psnr
img1 = cv2.imread('img1.jpg')
img2 = cv2.imread('img2.jpg')
# mean squared error
compare_mse(img1, img2)
# normalized root-mean-square
compare_nrmse(img1, img2)
# peak signal-to-noise ratio
compare_psnr(img1, img2)
# structural similarity index
compare_ssim(img1, img2, multichannel=True)
The images must have the same size.
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 8 years ago.
Improve this question
I work with image processing in OpenCV in python.
My main problem is light deflection. Can these deflections be removed with some method?
I implemented a lot of code here, but cant find this particular lights deflections effect. 1)I implemented grayscale, sobel filter, median blur, histogram analysis for plates detections, but this deflections cause that my histogram is bad for edges from sobel filtering, removing these flashes cause that it should works good.
An input image:
Use a colorspace transformation. For instance, if you transform your image to the HSV space, you'll see the "light" components in the V("value") channel:
This is the HSV image:
This is the V channel:
This is the regions of the V channel above a certain level (i.e. a thresholded image):
Now, you can use this kind of stuff to get things done by removing the high values of this V channel, then merging the channels back again. Good luck!
NOTE: as you see, I'm not giving you the code. I think that this should be easy to program if you search the documentation on OpenCV's cvtColor, split/merge or threshold methods ;)