opencv python- noise in saved image via io.imsave - python

i am trying to save an image in opencv python. the image that the program is showing via cv2.imshow() is perfectly fine. but when i am saving it using cv2.imwrite() it is saving black image .then i have tried io.imsave for saving but it is also saving my image with some gray small blobs on that.
i am saving it with .png extension.i have also tried to save with other extensions but nothing works fine for me.
cv2.imshow('result',res)
io.imsave('gabor.png',res)
can anyone point out what can be the problem?

Related

How do I work with the mask data for AI4 boundaries?

I am working with the Ai4Boundaries dataset and while the data in the imagery folder is opening with Windows Photos + causing no issues in the python code I'm reading it into, the data in the mask folder will only open on ArcMap (as a black-blue gradient) and is causing errors in my code. (Both the imagery and the mask are in tiff format).
Here is a link to the
Imagery
Masks
When I simply try and open a mask using python with this code
plt.imshow(mpimg.imread('/content/AT_2989_ortholabel_1m_512.tif'))
the error I get is
UnidentifiedImageError: cannot identify image file '/content/AT_2989_ortholabel_1m_512.tif'
Any leads as to what the issue is and how I can resolve it?
I tried converting a mask to png and the png file is working fine on my code. But I'm working with around 7k+ images and don't know how to bulk convert.

Saving an image as jpg gives me plain black

I am implementing gabor kernels, when I display the kernels while running the code (before saving them) they give me a picture like this
But after saving the kernels as jpg images using cv2.imwrite, I get like that
Any explanations? and how to save the kernels as in the first image?
There could be different causes. So I have two suggestions:
If you display the first picture with plt.imshow(), export it with plt.savefig(). This should easily be working.
If you still want to export the image with cv2.imwrite() make sure that the picture is correctly rescaled first. (mind that if you have only one channel, you will get a grayscale picture).
If we call the original picture org_img:
img = org_img
min_val,max_val=img.min(),img.max()
img = 255.0*(img - min_val)/(max_val - min_val)
img = img.astype(np.uint8)
cv2.imwrite(img,"picture.png")

python: when reading and saving a image the color change

I tried loading and saving images with python using cv2,PIL, scipy , but the saved image has a bit different color compare to the original.
I am loading and saving tif format, so i expect no color change.
link to the image I am using:
https://data.csail.mit.edu/graphics/fivek/img/tiff16_c/a0486-jmac_MG_0791.tif
the difference between loaded image and saved image is:
can you help me understand what I am doing wrong? why the color change?
update:
the problem is because the image is prophoto rgb color.
does anyone knows how can i convert a batch of images from prophoto rgb to rgb?
thanks,
yoav
option 1:
img = imread(file_name)
imsave('imread.tif', img)
option 2:
img = cv2.imread(file_name)
cv2.imwrite('cv2.tif', img)
option 3:
img = Image.open(file_name)
img.save('pil.tif')
I think OpenCV is more interested in Computer Vision - i.e. detecting and measuring objects etc than printing or high quality image reproduction, editing and printing, so it pretty much ignores ICC profiles. If anyone knows better, I am happy to be corrected.
You can use ImageMagick to convert images from one format to another, and to do many, many other things, one of which is changing colour profiles. So, I think, if you go to this website and download an sRGB profile (I chose the first one with "preference" in its name) and save it as sRGB.icc, you can change one of your ProPhoto images to a normal sRGB image with the following command in Terminal:
convert input.tif -profile sRGB.icc output.tiff
Try that and see if it works. If so, make a copy of your images and on a copy, you can run mogrify to do the whole lot in one go - beware and make a copy like I suggest because it will very quickly alter all your images...
magick mogrify -profile sRGB.icc *tif
You can see the embedded profile and loads of other information about an image using ImageMagick's identify command:
magick identify -verbose OneOfYourImages.tiff

Fill broken parts of an image using Python, OpenCV

I have a Captcha image like this:Captcha image
And Im writing a program to read it. Before any ML work I want to fill the parts where the image is broken. How do I do this?

Reading tiffs in opencv swaps top and bottom third of image

I've got a pretty strange issue. I have several tif images of astronomical objects. I'm trying to use opencv's python bindings to process them. Upon reading the image file, it appears that segments of the images are swapped or rotated. I've stripped it down to the bare minimum, and it still reproduces:
img = cv2.imread('image.tif', 0)
cv2.imwrite('image_unaltered.tif', img)
I've uploaded some samples to imgur, to show the effect. The images aren't super clear, that's the nature of preprocessed astronomical images, but you can see it:
First set:
http://imgur.com/vXzRQvS
http://imgur.com/wig99KR
Second set:
http://imgur.com/pf7tnPz
http://imgur.com/xGn9C77
The same rotated/swapped images appear if I use cv2.imShow(...) as well, so I believe it's something when I read the file. Furthermore, it persists if I save as jpg as well. Opening the original in Photoshop shows the correct image. I'm using opencv 2.4.10, on Linux Mint 17.1. If it matters, the original tifs were created with FITS liberator on windows.
Any idea what's happening here?

Categories

Resources