Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: Base.show for OpenCV.Mat image #30

Closed
rakeshksr opened this issue Oct 1, 2023 · 2 comments · Fixed by #35
Closed

Feature request: Base.show for OpenCV.Mat image #30

rakeshksr opened this issue Oct 1, 2023 · 2 comments · Fixed by #35

Comments

@rakeshksr
Copy link
Member

@ashwani-rathee

It's good to have Base.show method to display images in pluto.jl directly.

Currently, I implemented a simple(hacky) method for my needs to show images in pluto.jl

using ImageIO
using ImageShow
using ImageCore
using OpenCV

function Base.show(io::IO, ::MIME"image/png", opencv_img::OpenCV.Mat{UInt8})
	# opencv_img = OpenCV.cvtColor(opencv_img, OpenCV.COLOR_BGR2RGB)
	prmt_img::Array{UInt8, 3} = permutedims(opencv_img, (1, 3, 2))
	if size(prmt_img, 1) == 1
		img2d = dropdims(prmt_img; dims=1)
		img = colorview(Gray, float.(img2d)./255)
	else
		img = colorview(RGB, float.(prmt_img)./255)
	end
		
	Base.show(io, MIME"image/png"(), img)
end
@ashwani-rathee
Copy link
Member

Can you please make a PR? I would love to get it in

@rakeshksr
Copy link
Member Author

IMO depending on ImageIO.jl, ImageShow.jl and ImageCore.jl for Base.show makes OpenCV.jl little heavy. From what I understood correctly, ImageShow/showmime.jl uses FileIO.jl for Base.show methods.

Why don't follow similar approach by adding FileIo.jl integration with opencv.jl then write Base.show method on top of that?
This makes OpenCV.jl not depends on ImageIO, ImageShow and ImageCore.

Maybe we can depends on ImageCore for OpenCV.jl <=> Images.jl conversion in future.

@rakeshksr rakeshksr changed the title Feature request: Base.show for OpenCV.Mat image Feature request: Base.show for OpenCV.Mat image Oct 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants