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
Virtualdragdrop - Virtual Drag and Drop Using OpenCV and Arduino

Virtualdragdrop - Virtual Drag and Drop Using OpenCV and Arduino

Rizky Dermawan 4 Mar 10, 2022
第一届西安交通大学人工智能实践大赛(2018AI实践大赛--图片文字识别)第一名;仅采用densenet识别图中文字

OCR 第一届西安交通大学人工智能实践大赛(2018AI实践大赛--图片文字识别)冠军 模型结果 该比赛计算每一个条目的f1score,取所有条目的平均,具体计算方式在这里。这里的计算方式不对一句话里的相同文字重复计算,故f1score比提交的最终结果低: - train val f1score 0

尹畅 441 Dec 22, 2022
Detect textlines in document images

Textline Detection Detect textlines in document images Introduction This tool performs border, region and textline detection from document image data

QURATOR-SPK 70 Jun 30, 2022
Solution for Problem 1 by team codesquad for AIDL 2020. Uses ML Kit for OCR and OpenCV for image processing

CodeSquad PS1 Solution for Problem Statement 1 for AIDL 2020 conducted by @unifynd technologies. Problem Given images of bills/invoices, the task was

Burhanuddin Udaipurwala 111 Nov 27, 2022
Code for the paper STN-OCR: A single Neural Network for Text Detection and Text Recognition

STN-OCR: A single Neural Network for Text Detection and Text Recognition This repository contains the code for the paper: STN-OCR: A single Neural Net

Christian Bartz 496 Jan 05, 2023
M-LSDを用いて四角形を検出し、射影変換を行うサンプルプログラム

M-LSD-warpPerspective-Example M-LSDを用いて四角形を検出し、射影変換を行うサンプルプログラムです。 Requirements OpenCV 3.4.2 or Later tensorflow 2.4.1 or Later Usage 実行方法は以下です。 pytho

KazuhitoTakahashi 9 Oct 14, 2022
2 telegram-bots: for image recognition and for text generation

💻 📱 Telegram_Bots 🔎 & 📖 2 telegram-bots: for image recognition and for text generation. About Image recognition bot: User sends a photo and bot de

Marina Polukoshko 1 Jan 27, 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
Tesseract Open Source OCR Engine (main repository)

Tesseract OCR About This package contains an OCR engine - libtesseract and a command line program - tesseract. Tesseract 4 adds a new neural net (LSTM

48.4k Jan 09, 2023
Python library to extract tabular data from images and scanned PDFs

Overview ExtractTable - API to extract tabular data from images and scanned PDFs The motivation is to make it easy for developers to extract tabular d

Org. Account 165 Dec 31, 2022
An Implementation of the alogrithm in paper IncepText: A New Inception-Text Module with Deformable PSROI Pooling for Multi-Oriented Scene Text Detection

InceptText-Tensorflow An Implementation of the alogrithm in paper IncepText: A New Inception-Text Module with Deformable PSROI Pooling for Multi-Orien

GeorgeJoe 115 Dec 12, 2022
Official code for :rocket: Unsupervised Change Detection of Extreme Events Using ML On-Board :rocket:

RaVAEn The RaVÆn system We introduce the RaVÆn system, a lightweight, unsupervised approach for change detection in satellite data based on Variationa

SpaceML 35 Jan 05, 2023
Repository relating to the CVPR21 paper TimeLens: Event-based Video Frame Interpolation

TimeLens: Event-based Video Frame Interpolation This repository is about the High Speed Event and RGB (HS-ERGB) dataset, used in the 2021 CVPR paper T

Robotics and Perception Group 544 Dec 19, 2022
A tool to make dumpy among us GIFS

Among Us Dumpy Gif Maker Made by ThatOneCalculator & Pixer415 With help from Telk, karl-police, and auguwu! Please credit this repository when you use

Kainoa Kanter 535 Jan 07, 2023
A simple Security Camera created using Opencv in Python where images gets saved in realtime in your Dropbox account at every 5 seconds

Security Camera using Opencv & Dropbox This is a simple Security Camera created using Opencv in Python where images gets saved in realtime in your Dro

Arpit Rath 1 Jan 31, 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
Vietnamese Language Detection and Recognition

Table of Content Introduction (Khôi viết) Dataset (đổi link thui thành 3k5 ảnh mình) Getting Started (An Viết) Requirements Usage Example Training & E

6 May 27, 2022
Code for CVPR2021 paper "Learning Salient Boundary Feature for Anchor-free Temporal Action Localization"

AFSD: Learning Salient Boundary Feature for Anchor-free Temporal Action Localization This is an official implementation in PyTorch of AFSD. Our paper

Tencent YouTu Research 146 Dec 24, 2022
An unofficial package help developers to implement ZATCA (Fatoora) QR code easily which required for e-invoicing

ZATCA (Fatoora) QR-Code Implementation An unofficial package help developers to implement ZATCA (Fatoora) QR code easily which required for e-invoicin

TheAwiteb 28 Nov 03, 2022
基于图像识别的开源RPA工具,理论上可以支持所有windows软件和网页的自动化

SimpleRPA 基于图像识别的开源RPA工具,理论上可以支持所有windows软件和网页的自动化 简介 SimpleRPA是一款python语言编写的开源RPA工具(桌面自动控制工具),用户可以通过配置yaml格式的文件,来实现桌面软件的自动化控制,简化繁杂重复的工作,比如运营人员给用户发消息,

Song Hui 7 Jun 26, 2022