hoffstadt / DearPyGui

Dear PyGui: A fast and powerful Graphical User Interface Toolkit for Python with minimal dependencies
https://dearpygui.readthedocs.io/en/latest/
MIT License
12.93k stars 675 forks source link

add texture filter/interpolation options for nearest neighbor #773

Open west-rynes opened 3 years ago

west-rynes commented 3 years ago

Describe the solution you'd like Currently textures appear to use linear interpolation by default. It would be great if we had the option to specify nearest neighbor interpolation as an option. At times. for certain applications this is more appropriate. I think most of the graphics backends allow specifying a texture filter option. This would be valuable for both the draw_image and image_series plots.

hoffstadt commented 3 years ago

Interesting. I was waiting on someone to request this!

CaiusTSM commented 3 years ago

Hello, I too require texture filtering options since I want to draw some images scaled up, but with nearest filtering.

hoffstadt commented 2 years ago

We are expecting this is 1.3. It will be a bit easier than we thought originally (learned some more advanced imgui features that will help)!

west-rynes commented 2 years ago

That will be great. Glad it’s not too much work. Thank you.

Moonspire commented 2 years ago

That's really good to hear! Keep us posted on the progress on this please =)

JonathanZhuMD commented 2 years ago

Any update on this feature yet?

west-rynes commented 2 years ago

I’m definitely looking forward to being able to have the option for nearest interpolation.

JonathanZhuMD commented 2 years ago

Actually, I'm just looking for a way to disable all any kind of interpolation at once, not sure if that'll be easier or not.

For nearest neighbor, why don't you create a simple 3x3 kernel with open CV and do the upscaling yourself?

west-rynes commented 2 years ago

@JonathanZhuMD I have an image viewer that the user zooms into. So I really don’t want to pre scale sub windows and then send it to textures. I just want the user to see to be able to zoom and see pixel boundaries. Nearest neighbor is really the equivalent of turning off interpolation.

wlwatkins commented 1 year ago

i've reposted a similar question https://github.com/hoffstadt/DearPyGui/issues/1915 , has there been any news? we are at v 1.7, but i don't think this has been implemented

hoffstadt commented 1 year ago

It has not been implemented yet. We do still plan on doing so for the 1.x version. It's one of the last bigger features for 1.0.

wlwatkins commented 1 year ago

I know it's an annoying question, but any clue of the timeline? asking to know whether i should keep with the low performance heatmap or in i can start implementing the image expecting the feature

keck-in-space commented 1 year ago

Just piping in to say we'd love to see this! Thanks!

west-rynes commented 1 year ago

I agree, would be wonderful to have for scientific applications

wlwatkins commented 1 year ago

any news about this? is there a way i coud help?

JonathanZhuMD commented 1 year ago

I don't think there any official update on this matter yet. I manage to circumvent the issue by manually upscale the image by a pre-determined factor; however it does uses much more memory since I'm sharing frames across processes with sharedmem. Sent from my iPhoneOn Mar 31, 2023, at 16:23, Will @.***> wrote: any news about this? is there a way i coud help?

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you were mentioned.Message ID: @.***>

west-rynes commented 1 year ago

I don't think there any official update on this matter yet. I manage to circumvent the issue by manually upscale the image by a pre-determined factor; however it does uses much more memory since I'm sharing frames across processes with sharedmem. Sent from my iPhoneOn Mar 31, 2023, at 16:23, Will @.> wrote: any news about this? is there a way i coud help? —Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you were mentioned.Message ID: @.>

That is definitely a good option if your images are not too big. For the data I’m working with the images are huge so it just isn’t feasible unless I do a bunch of sub windowing with zooming and then upscale g which seems a bit overboard.

JonathanZhuMD commented 1 year ago

Same here actually. We have 4 camera streams we need to display together.

We ended up purchased a few of the macStudio with 128GB RAM; it will be nice if there is a low-cost option to solve the problem though lol.

On Mar 31, 2023, at 4:37 PM, Anthony Tanbakuchi @.***> wrote:

I don't think there any official update on this matter yet. I manage to circumvent the issue by manually upscale the image by a pre-determined factor; however it does uses much more memory since I'm sharing frames across processes with sharedmem. Sent from my iPhoneOn Mar 31, 2023, at 16:23, Will @.> wrote: any news about this? is there a way i coud help? —Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you were mentioned.Message ID: @.>

That is definitely a good option if your images are not too big. For the data I’m working with the images are huge so it just isn’t feasible unless I do a bunch of sun windowing with zooming and then upscale g which seems a bit overboard.

— Reply to this email directly, view it on GitHub https://github.com/hoffstadt/DearPyGui/issues/773#issuecomment-1492639702, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACB5NYI6BYSBYMVLHUH6C4TW65FDDANCNFSM42G6TOMA. You are receiving this because you were mentioned.

Yosh31207 commented 1 year ago

A workaround is to modify the source code of DearPyGui and build it by yourself.

NOTICE: this changes the behavior of DearPyGui, so I recommend using venv so that the scope of influence is limited to your project.

I explain the procedure for Windows.

  1. Install Visual Studio.

    You need to install Desktop development with C++.

  2. Clone the DearPyGui repository.

  3. Modify the source code as follows.

    File: <repo_root>/thirdparty/imgui/backends/imgui_impl_dx11.cpp

    Change: replace D3D11_FILTER_MIN_MAG_MIP_LINEAR with D3D11_FILTER_MIN_MAG_MIP_POINT

    This changes the default behavior of Dear ImGui which DearPyGui uses.

  4. Modify the build script setup.py if you use a version of Visual Studio other than Visual Studio 2019.

    Modify the CMake path and cmake option. For a case of Visual Studio 2022, replace Visual Studio 16 2019 in the cmake option with Visual Studio 17 2022.

  5. Run the build script with build option.

    python setup.py build

  6. Copy the built _dearpygui.pyd file to the site-package directory.

    If you use venv, the destination path would be:

    <venv_dir>/Lib/site-packages/dearpygui/_dearpygui.pyd

I built with Visual Studio 2022 successfully, but not sure if it can be built with compilers older than Visual Studio 2019.

bo-at-pleno commented 1 month ago

To add to Yosh31207 - on Mac the file is imgui_impl_metal.mm

fragment half4 fragment_main(VertexOut in [[stage_in]],
                             texture2d<half, access::sample> texture [[texture(0)]]) {
    constexpr sampler nearestSampler(coord::normalized, min_filter::nearest, mag_filter::nearest, mip_filter::nearest);
    half4 texColor = texture.sample(nearestSampler, in.texCoords);
    return half4(in.color) * texColor;
}