Crop regions in napari manually

Overview

napari-crop

License PyPI Python Version tests codecov

Crop regions in napari manually

Usage

Create a new shapes layer to annotate the region you would like to crop:

Use the rectangle tool to annotate a region. Start the crop tool from the Tools > Utilities > Crop region menu. Click the Run button to crop the region.

You can also use the Select shapes tool to move the rectangle to a new place and crop another region by clicking on Run.

Hint: You can also use the napari-tabu plugin to send all your cropped images to a new napari window.


This napari plugin was generated with Cookiecutter using with @napari's cookiecutter-napari-plugin template.

Installation

You can install napari-crop via pip:

pip install napari-crop

Contributing

Contributions are very welcome.

License

Distributed under the terms of the BSD-3 license, "napari-crop" is free and open source software

Issues

If you encounter any problems, please create a thread on image.sc along with a detailed description and tag @haesleinhuepf.

Comments
  • Return list of LayerDataTuple instead of single layers

    Return list of LayerDataTuple instead of single layers

    I implemented these changes to try to solve #6, returning several layers for several drawn shapes, but it is still not working.

    The motivation for this is explained here and there is indication that this approach has been implemented here.

    Does any of you guys have ideas to make this work? @haesleinhuepf @tdmorello

    opened by zoccoler 16
  • Make cropper RGB friendly, N-dimensional, and sliceable from any orthogonal viewpoint

    Make cropper RGB friendly, N-dimensional, and sliceable from any orthogonal viewpoint

    Hi Robert,

    First of all, consider me a big fan of your napari plugins -- I really appreciate the number of tools you are creating and publishing for napari users!

    Second, I was testing out this plugin and found it wasn't working on RGB images, so I dug into the code a little bit and thought of some ways to (hopefully) make it applicable to more scenarios. If you get some time to test it out, I'd really appreciate it!

    I think the key features are:

    1. it works with any number of dimensions
    2. you can draw a cropping region in an orthogonal view (e.g. XZ plane) and it'll give you the expected results
    3. the slice indices aren't hard-coded, so it should be a little easier to maintain and adapt

    I also wrote some tests to help my dev'ing (and hope they will be useful to the repo as well).

    Finally, I see @zoccoler 's PR and am planning on trying to fit my changes in with his (polygon cropping). The code I'm sharing can be easily modified to output more than 1 new layer when multiple shapes are draw.

    Let me know what you think.

    Best, Tim

    opened by tdmorello 7
  • removed python 3.7 and opencl from github CI

    removed python 3.7 and opencl from github CI

    I think this should fix #28 but I can't know for sure until I've started a run of the github CI.

    Edit: Tests are passing, switching to non-draft mode.

    Fixes #28

    bug enhancement 
    opened by jo-mueller 5
  • Cropped ellipses sometimes show a black line of pixels

    Cropped ellipses sometimes show a black line of pixels

    I have noticed that, for certain ellipses, the following cropped image is returned. This behavior is inconsistent: the line appears or not depending on where the ellipse is drawn.

    ellipse_bug

    opened by zoccoler 4
  • Tests are failing due to OpenGL installation in `test_and_deploy.yaml`

    Tests are failing due to OpenGL installation in `test_and_deploy.yaml`

    I'm not sure whether this installation is necessary for packages that do not rely on GPU-functionality. I'll start a PR to see if tests still pass after removing this part from test_and_deploy.yaml.

    opened by jo-mueller 3
  • Update README with new example

    Update README with new example

    Hey Robert @haesleinhuepf

    Here's a new example. I didn't match your style with the highlight circle around the cursor -- I hope that's ok. The url to the animation will have to change before merge.

    opened by tdmorello 3
  • Crop all shapes

    Crop all shapes

    Hi Robert @haesleinhuepf

    I modified the function adding 2 new functionalities:

    1. if more than one shape is drawn in the layer shape, it crops all shapes and adds them as new layers;
    2. if the shapes have irregular shapes (like ellipses or polygons), it crops according to that shape, clearing pixels outside the shape;
    • I also changed a little the extent of the shapes position and size (from .astype(int) to np.ceil or np.around) to ensure the irregular drawn shape would be entirely captured;

    Please let me know if it works and if you have suggestions/improvements to the code 😃

    opened by zoccoler 3
  • Give cropped layers unique names

    Give cropped layers unique names

    Hi guys,

    This Draft PR is intended to fix #20 . The problem happened because after #7 because here we always assigned the same name for drawn shapes from the same Shapes layer, thus, napari replaces previous output Image layer data instead of creating a new layer if the function was executed again.

    The proposed solution is to always provide a new unique name by checking layer names in the viewer (or layer names about to be added to the viewer in case of multiple shapes).

    It works here. I will write a test before turning this into regular PR.

    Best, Marcelo

    opened by zoccoler 2
  • Shape error for irregular shapes drawn close to image edge

    Shape error for irregular shapes drawn close to image edge

    Applying crop to shapes like these:

    import numpy as np
    arr_2d = np.arange(0, 25).reshape((5, 5))
    shapes = [
        np.array([[1, 1], [1, 3], [5, 3], [5, 1]]),
        np.array([[0.5, 0.5], [0.5, 3.5], [4.51, 3.5], [4.51, 0.5]]),
        np.array([[0, 2], [5, 5], [5, 2], [2, 0]]),
        
    ]
    shape_types = ["rectangle", "ellipse", "polygon"]
    
    viewer.add_image(arr_2d)
    shapes_layer = viewer.add_shapes(shapes, shape_type=shape_types, edge_width=0)
    

    shapes

    Only works with the rectangle. For irregular shapes drawn close or over image edge, it gives an error like this:

    ValueError: operands could not be broadcast together with remapped shapes [original->remapped]: (6,6)  and requested shape (5,5)
    
    opened by zoccoler 2
  • make crop_region part of the public API

    make crop_region part of the public API

    Hi all,

    does anybody see issues if we make crop_region part of the public API?

    E.g. like this:

    from napari_crop import crop_region
    

    We could then use it from scripts as discssed in this thread.

    Let me know what you think! If there are no concerns, I would just open the API.

    Best, Robert

    opened by haesleinhuepf 1
  • Bug/labels

    Bug/labels

    Fixes a problem where Labels layers could not be cropped.

    The crop_region function was looking for layer_props["rgb"] raising a KeyError with Labels layers.

    Also, adding a test for cropping Labels.

    opened by tdmorello 1
  • Support if image layers to Crop from have an .affine transform property

    Support if image layers to Crop from have an .affine transform property

    Both the image layer to crop from and the shape layer defining the crop regions could have an .affine property. I don't think these are currently taken into account.

    enhancement 
    opened by VolkerH 4
  • Dependency napari_workflows not specified in requirements or setup.cfg

    Dependency napari_workflows not specified in requirements or setup.cfg

    This seems to depend on https://github.com/haesleinhuepf/napari-workflows by @haesleinhuepf, but when installing the plugin, this dependency is not automatically installed.

    opened by VolkerH 3
  • Allow irregular nD crop

    Allow irregular nD crop

    Proposed enhancement

    napari-crop can crop in nD based on 2D shapes. It would be a good new feature to cut in irregular 3D shapes with the user providing points/shapes representing polygons at different z-slices.

    Example of the current behavior

    The code below is an attempt to reproduce it in the current state.

    import napari
    from napari_crop._function import crop_region
    from skimage.data import cells3d
    import numpy as np
    from magicgui import magicgui
    
    viewer = napari.Viewer()
    image = cells3d()
    image = image[:,1]
    
    polygon1 = np.array([[ 24., 141., 100.],
                        [ 24., 135., 115.],
                        [ 24., 142., 130.],
                        [ 24., 155., 134.],
                        [ 24., 167., 129.],
                        [ 24., 173., 117.],
                        [ 24., 163., 103.],
                        [ 24., 156.,  95.]])
    
    polygon2 = np.array([[ 33. , 136., 102.],
                        [ 33., 132., 115.7],
                        [ 33., 152., 135.],
                        [ 33., 165., 134.],
                        [ 33., 176., 122.],
                        [ 33., 180., 112.],
                        [ 33., 160.,  89.],
                        [ 33., 140.,  95.]])
    
    polygon3 = np.array([[ 45., 146., 94.],
                        [ 45., 143., 109.],
                        [ 45., 156., 122.],
                        [ 45., 170., 126.],
                        [ 45., 179., 120.],
                        [ 45., 182., 108.],
                        [ 45., 177.,  99.],
                        [ 45., 154.,  89.]])
    
    # This is how the shapes layer data would be if the user draw polygons along a z-stack
    polygon_list = [polygon1, polygon2, polygon3]
    
    # Transforms a list of polygons into a single 3D array of vertices
    shapes = [polygon[np.newaxis,:] for polygon in polygon_list]
    shape_3D = np.concatenate(shapes, axis=0)
    
    viewer.add_image(image)
    viewer.add_shapes(np.array(shape_3D), shape_type='polygon')
    
    widget = magicgui(crop_region)
    viewer.window.add_dock_widget(widget)
    

    Two errors happen:

    1. If the number of vertices per slice is not the same, there is a ValueError because the polygons cannot be concatenated into a 3D array with the same shape.
    2. Even if the number of vertices match, it gives an interpolation error: ValueError: 'linear' is not a valid Interpolation

    From this, it seems the shapes layer may not be the best choice for that. Turning it into a surface and cropping it seems more appropriate. Suggestions and feedback welcome :)

    enhancement 
    opened by zoccoler 0
  • Crop in time

    Crop in time

    I believe napari-crop should be able to handle time crops as well. It is just a matter of properly slicing, right? For that case, maybe relying on the shapes layer wouldn't be so intuitive from the user point of view.

    My first thought would be to add 2 spinboxes for start end end of time slice. It could be a rangeslider as well. Enabling this by means of a checkbox, or even better if the type of data can be auto-detected.

    What do you guys think?

    enhancement 
    opened by zoccoler 0
  • Cropping on large images does not give expected results

    Cropping on large images does not give expected results

    I have an 10888 x 6451 px image. When I draw small crops, it works as expected. When I draw large crops, the output shapes are not as expected.

    E.g. Crop shape = 9917 x 5423 output shape = 9025 x 4164

    Maybe it has something to do with how the image data is tiled in memory?

    When I crop a region that extends beyond the bounds of the image to get the whole image, it works as expected.

    opened by tdmorello 0
Releases(0.1.6)
  • 0.1.6(Jul 25, 2022)

    What's Changed

    • make crop_region public by @haesleinhuepf in https://github.com/BiAPoL/napari-crop/pull/23
    • Give cropped layers unique names by @zoccoler in https://github.com/BiAPoL/napari-crop/pull/24
    • fix axes order from viewer by @zoccoler in https://github.com/BiAPoL/napari-crop/pull/26
    • Unique layer names by @zoccoler in https://github.com/BiAPoL/napari-crop/pull/31 (actually brings PR #26 into main)

    Full Changelog: https://github.com/BiAPoL/napari-crop/compare/0.1.5...0.1.6

    Source code(tar.gz)
    Source code(zip)
  • 0.1.5(Jan 5, 2022)

    New features

    • Crop multiple shapes (Thanks to @zoccoler and @tdmorello for implementing this)

    Note: The repository location changed. It's now https://github.com/BiAPoL/napari-crop

    Source code(tar.gz)
    Source code(zip)
  • 0.1.4(Dec 27, 2021)

    New features

    • Supports more image shapes and RGB data
    • Supports cropping polygons

    Big thanks to Tim Morello @tdmorello and Marcelo Leomil Zoccoler @zoccoler for working on this!

    Source code(tar.gz)
    Source code(zip)
  • 0.1.3(Oct 26, 2021)

  • 0.1.2(Oct 21, 2021)

  • 0.1.1(Oct 21, 2021)

  • 0.1.0(Oct 21, 2021)

Owner
Robert Haase
Computational Microscopist, BioImage Analyst, Code Jockey
Robert Haase
Page to PAGE Layout Analysis Tool

P2PaLA Page to PAGE Layout Analysis (P2PaLA) is a toolkit for Document Layout Analysis based on Neural Networks. 💥 Try our new DEMO for online baseli

Lorenzo Quirós Díaz 180 Nov 24, 2022
scantailor - Scan Tailor is an interactive post-processing tool for scanned pages.

Scan Tailor - scantailor.org This project is no longer maintained, and has not been maintained for a while. About Scan Tailor is an interactive post-p

1.5k Dec 28, 2022
A general list of resources to image text localization and recognition 场景文本位置感知与识别的论文资源与实现合集 シーンテキストの位置認識と識別のための論文リソースの要約

Scene Text Localization & Recognition Resources Read this institute-wise: English, 简体中文. Read this year-wise: English, 简体中文. Tags: [STL] (Scene Text L

Karl Lok (Zhaokai Luo) 901 Dec 11, 2022
Pixel art search engine for opengameart

Pixel Art Reverse Image Search for OpenGameArt What does the final search look like? The final search with an example can be found here. It looks like

Eivind Magnus Hvidevold 92 Nov 06, 2022
Python-based tools for document analysis and OCR

ocropy OCRopus is a collection of document analysis programs, not a turn-key OCR system. In order to apply it to your documents, you may need to do so

OCRopus 3.2k Dec 31, 2022
Um simples projeto para fazer o reconhecimento do captcha usado pelo jogo bombcrypto

CaptchaSolver - LEIA ISSO 😓 Para iniciar o codigo: pip install -r requirements.txt python captcha_solver.py Se você deseja pegar ver o resultado das

Kawanderson 50 Mar 21, 2022
Fun program to overlay a mask to yourself using a webcam

Superhero Mask Overlay Description Simple project made for fun. It consists of placing a mask (a PNG image with transparent background) on your face.

KB Kwan 10 Dec 01, 2022
Pytorch implementation of PSEnet with Pyramid Attention Network as feature extractor

Scene Text-Spotting based on PSEnet+CRNN Pytorch implementation of an end to end Text-Spotter with a PSEnet text detector and CRNN text recognizer. We

azhar shaikh 62 Oct 10, 2022
Source Code for AAAI 2022 paper "Graph Convolutional Networks with Dual Message Passing for Subgraph Isomorphism Counting and Matching"

Graph Convolutional Networks with Dual Message Passing for Subgraph Isomorphism Counting and Matching This repository is an official implementation of

HKUST-KnowComp 13 Sep 08, 2022
This is a project to detect gestures to zoom in or out, using the real-time distance between the index finger and the thumb. It's based on OpenCV and Mediapipe.

Pinch-zoom This is a python project based on real-time hand-gesture detection, to zoom in or out, using the distance between the index finger and the

Harshit Bhalla 6 Jul 11, 2022
Fusion 360 Add-in that creates a pair of toothed curves that can be used to split a body and create two pieces that slide and lock together.

Fusion-360-Add-In-PuzzleSpline Fusion 360 Add-in that creates a pair of toothed curves that can be used to split a body and create two pieces that sli

Michiel van Wessem 1 Nov 15, 2021
原神风花节自动弹琴辅助

GenshinAutoPlayBalladsofBreeze 原神风花节自动弹琴辅助(已适配1920*1080分辨率) 本程序基于opencv图像识别技术,不存在任何封号。 因为正确率取决于你的cpu性能,10900k都不一定全对。 由于图像识别存在误差,根本无法确定出错时间。更不用说被检测到了。

晓轩 20 Oct 27, 2022
Handwritten Character Recognition using CNN

Handwritten Character Recognition using CNN Problem Definition The main objective of this project is to solve the problem of handwritten character rec

Mohit Kaushik 4 Mar 02, 2022
governance proposal to make fei redeemable for eth

Feil Proposal 🌲 Abstract Migrate all ETH from Fei protocol-controlled value into Yearn ETH Vault. Allow redemptions of outstanding FEI for yvETH. At

13 Mar 31, 2022
Hiiii this is the Spanish for Linux and win 10 and in the near future the english version of PortScan my new tool on which you can see what ports are Open only with the IP adress.

PortScanner-by-IIT PortScanner es una herramienta programada en Python3. Como su nombre indica esta herramienta escanea los primeros 150 puertos de re

5 Sep 19, 2022
Generates a message from the infamous Jerma Impostor image

Generate your very own jerma sus imposter message. Modes: Default Mode: Only supports the characters " ", !, a, b, c, d, e, h, i, m, n, o, p, q, r, s,

Giorno420 1 Oct 27, 2022
Simple app for visual editing of Page XML files

Name nw-page-editor - Simple app for visual editing of Page XML files. Version: 2021.02.22 Description nw-page-editor is an application for viewing/ed

Mauricio Villegas 27 Jun 20, 2022
~1000 book pages + OpenCV + python = page regions identified as paragraphs, lines, images, captions, etc.

cosc428-structor I had an open-ended Computer Vision assignment to complete, and an out-of-copyright book that I wanted to turn into an ebook. Convent

Chad Oliver 45 Dec 06, 2022
Code release for our paper, "SimNet: Enabling Robust Unknown Object Manipulation from Pure Synthetic Data via Stereo"

SimNet: Enabling Robust Unknown Object Manipulation from Pure Synthetic Data via Stereo Thomas Kollar, Michael Laskey, Kevin Stone, Brijen Thananjeyan

68 Dec 14, 2022
Localization of thoracic abnormalities model based on VinBigData (top 1%)

Repository contains the code for 2nd place solution of VinBigData Chest X-ray Abnormalities Detection competition. The goal of competition was to auto

33 May 24, 2022