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
This is an API written in python that uses FastAPI. It is a simple API that can detect discord tokens in Images.

Welcome This is an API written in python that uses FastAPI. It is a simple API that can detect discord tokens in Images. Installation There are curren

8 Jul 29, 2022
[EMNLP 2021] Improving and Simplifying Pattern Exploiting Training

ADAPET This repository contains the official code for the paper: "Improving and Simplifying Pattern Exploiting Training". The model improves and simpl

Rakesh R Menon 138 Dec 26, 2022
Convolutional Recurrent Neural Network (CRNN) for image-based sequence recognition.

Convolutional Recurrent Neural Network This software implements the Convolutional Recurrent Neural Network (CRNN), a combination of CNN, RNN and CTC l

Baoguang Shi 2k Dec 31, 2022
computer vision, image processing and machine learning on the web browser or node.

Image processing and Machine learning labs   computer vision, image processing and machine learning on the web browser or node note Fast Fourier Trans

ryohei tanaka 487 Nov 11, 2022
A pkg stiching around view images(4-6cameras) to generate bird's eye view.

AVP-BEV-OPEN Please check our new work AVP_SLAM_SIM A pkg stiching around view images(4-6cameras) to generate bird's eye view! View Demo · Report Bug

Xinliang Zhong 37 Dec 01, 2022
A toolbox of scene text detection and recognition

FudanOCR This toolbox contains the implementations of the following papers: Scene Text Telescope: Text-Focused Scene Image Super-Resolution [Chen et a

FudanVIC Team 170 Dec 26, 2022
Brief idea about our project is mentioned in project presentation file.

Brief idea about our project is mentioned in project presentation file. You just have to run attendance.py file in your suitable IDE but we prefer jupyter lab.

Dhruv ;-) 3 Mar 20, 2022
A simple Digits Recogniser made in Python

⭐ Python Digit Recogniser A simple digit Recogniser made in Python Demo Run Locally Clone the project git clone https://github.com/yashraj-n/python-

Yashraj narke 4 Nov 29, 2021
A python program to block out your face

Readme This is a small program I threw together in about 6 hours to block out your face. It probably doesn't work very well, so be warned. By default,

1 Oct 17, 2021
Apply different text recognition services to images of handwritten documents.

Handprint The Handwritten Page Recognition Test is a command-line program that invokes HTR (handwritten text recognition) services on images of docume

Caltech Library 117 Jan 02, 2023
[python3.6] 运用tf实现自然场景文字检测,keras/pytorch实现ctpn+crnn+ctc实现不定长场景文字OCR识别

本文基于tensorflow、keras/pytorch实现对自然场景的文字检测及端到端的OCR中文文字识别 update20190706 为解决本项目中对数学公式预测的准确性,做了其他的改进和尝试,效果还不错,https://github.com/xiaofengShi/Image2Katex 希

xiaofeng 2.7k Dec 25, 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
Code for CVPR 2022 paper "SoftGroup for Instance Segmentation on 3D Point Clouds"

SoftGroup We provide code for reproducing results of the paper SoftGroup for 3D Instance Segmentation on Point Clouds (CVPR 2022) Author: Thang Vu, Ko

Thang Vu 231 Dec 27, 2022
Textboxes_plusplus implementation with Tensorflow (python)

TextBoxes++-TensorFlow TextBoxes++ re-implementation using tensorflow. This project is greatly inspired by slim project And many functions are modifie

81 Dec 07, 2022
Shape Detection - It's a shape detection project with OpenCV and Python.

Shape Detection It's a shape detection project with OpenCV and Python. Setup pip install opencv-python for doing AI things. pip install simpleaudio fo

1 Nov 26, 2022
CNN+LSTM+CTC based OCR implemented using tensorflow.

CNN_LSTM_CTC_Tensorflow CNN+LSTM+CTC based OCR(Optical Character Recognition) implemented using tensorflow. Note: there is No restriction on the numbe

Watson Yang 356 Dec 08, 2022
Omdena-abuja-anpd - Automatic Number Plate Detection for the security of lives and properties using Computer Vision.

Omdena-abuja-anpd - Automatic Number Plate Detection for the security of lives and properties using Computer Vision.

Abdulazeez Jimoh 1 Jan 01, 2022
RRD: Rotation-Sensitive Regression for Oriented Scene Text Detection

RRD: Rotation-Sensitive Regression for Oriented Scene Text Detection For more details, please refer to our paper. Citing Please cite the related works

Minghui Liao 102 Jun 29, 2022
Give a solution to recognize MaoYan font.

猫眼字体识别 该 github repo 在于帮助xjtlu的同学们识别猫眼的扭曲字体。已经打包上传至 pypi ,可以使用 pip 直接安装。 猫眼字体的识别不出来的原理与解决思路在采茶上 使用方法: import MaoYanFontRecognize

Aruix 4 Jun 30, 2022
Text page dewarping using a "cubic sheet" model

page_dewarp Page dewarping and thresholding using a "cubic sheet" model - see full writeup at https://mzucker.github.io/2016/08/15/page-dewarping.html

Matt Zucker 1.2k Dec 29, 2022