Python tips and tricks - 5: Extracting patches from large images and masks for semantic segmentation

Ғылым және технология

Link to my GitHub account:
github.com/bnsreenu/python_fo...

Пікірлер: 96

  • @chrisber
    @chrisber2 жыл бұрын

    I've recently stumbled upon your channel and it is absolutely excellent, thank you for all your great work!

  • @DigitalSreeni

    @DigitalSreeni

    2 жыл бұрын

    Welcome!

  • @aminulhuq6668
    @aminulhuq6668 Жыл бұрын

    I have been following your videos for a while. Your explanations on different image processing techniques and deep learning approaches are great. Thank you so much for the videos. I have request. Can you please make a video on patch based CNN for classification? Keep up the excellent work.

  • @louis-philip
    @louis-philip Жыл бұрын

    Love the way you explain everything man, thank you!

  • @Sean-yg3tr
    @Sean-yg3tr3 ай бұрын

    You should know how much of a blessing this is. Thank you very much.

  • @karangadgil9847
    @karangadgil98472 жыл бұрын

    what an easy way to do it! really struggled to get to this video. wish I found it sooner

  • @bSariturk
    @bSariturk3 жыл бұрын

    that's very helpful, thank you. i didn't know about this patchify library.

  • @v.lobanov
    @v.lobanov3 жыл бұрын

    Great advice, thanks! But what if not all objects are annotated within a patch, but you have an extent of annotated part? Is it possible to crop / turn into "no data" the rest of the patch?

  • @RedShipsofSpainAgain
    @RedShipsofSpainAgain2 жыл бұрын

    Excellent video! As Vasily asked in a previous comment, how do we handle cases where the patch boundary splits a mask such that the annotated object and mask exists across 2 (or more) adjacent patches? Should we choose a different patch size? Should we rerun patchify but with overlapping patches? What's the best practice? Thanks Sreeni

  • @niluparupasinghe6345
    @niluparupasinghe63453 жыл бұрын

    Really helpful, thanks for sharing your knowledge....

  • @hebayousif88
    @hebayousif882 жыл бұрын

    Thank you sir ,I just discovered your tutorials, they are brilliant. I am working with whole slide images segmentation, I do patch sampling and end up with three types of patches: completely normal patches, completely tumor patches and patches with a combination of both. My question is doesn't showing the model with completely white or black masks will trick the model and cause a loss in performance? due to the large size of WSI, there will be large areas (larger than the patch size) with all tumor regions?

  • @samjut3718
    @samjut37182 жыл бұрын

    Hi Sreeni, I have images and test sites polygons. do I need to convert the polygons to different formate before creating the subimages or patches for training with U-Net? Thank you

  • @lennertantson8050
    @lennertantson80502 жыл бұрын

    Just what I needed, thank you !

  • @DigitalSreeni

    @DigitalSreeni

    2 жыл бұрын

    You are so welcome!

  • @zzmirror4294
    @zzmirror42942 жыл бұрын

    hi, thanks for your wonderful trainings , I ussed this method for a rgb image , and my patch dimention is (1 , 256 , 256 , 3) I dont know how should I save it as image . can you help please ?

  • @منةالرحمن
    @منةالرحمن3 жыл бұрын

    Great always the best 💖

  • @sbsyr5555
    @sbsyr55553 жыл бұрын

    Thank you for sharing new one...

  • @vivekpatel3752
    @vivekpatel3752 Жыл бұрын

    Hi Sreeni, hope you are having a good dayCan you tell how to automatically mask all these objects in a large image. I am trying to replicate your code for random forest for anemia detection but I want a mask image with all RBC and sickle cells?

  • @bediosoro7786
    @bediosoro77863 жыл бұрын

    does patchify pads image if the image size is not a multiple of patch size?

  • @anjaliraj6456
    @anjaliraj6456 Жыл бұрын

    How do we deal with patchify when we have different numbers of bands for images(for eg, 10 bands image) and labels (for eg, 1 band mask file)?

  • @navinbondade5365
    @navinbondade53653 жыл бұрын

    Sir when are we going to work with audios, advance GANs and Auto-encoder models ?

  • @hungchu7840
    @hungchu78403 жыл бұрын

    Sir, could you please make a video about SGAN to improve the high resolution of images, it is really important to improve result of segmentation, while we apply these images for SGAN then apply U-net

  • @Iamanandraj
    @Iamanandraj2 жыл бұрын

    How to read large image (pixel is high and image size is 500mb), cv2 is giving error validate input image size. I have to do same work you done in this video but i am getting error in first step. I am getting error when i ma reading the image in opencv. Please help me

  • @fuegopuro5933
    @fuegopuro59333 жыл бұрын

    Hi Sreeni, could you please share your tutorial on semantic segmentation using LITS dataset?

  • @ankushjamthikar9780
    @ankushjamthikar97802 жыл бұрын

    I have a whole slide image. I want to get small patches from the WSI. Can you please share some details on how to do it?

  • @sumanabasu3339
    @sumanabasu3339 Жыл бұрын

    Hello Sreeni, I was trying to patchify my images (shape 128,128,3) [my original image is 1024, 1024, 3] and then after doing some operation, I tried unpatchify the image. But when unpathify the image, the boarder of the patched images are visible in the unpatched image. Could you please suggest how can I get rid of this artefact?

  • @alele5410
    @alele5410 Жыл бұрын

    Very interesting!! could you show satellite image classification using python please

  • @mohammadkarami8984
    @mohammadkarami89843 жыл бұрын

    Thank you very much for nice and concise video

  • @DigitalSreeni

    @DigitalSreeni

    3 жыл бұрын

    You are welcome!

  • @eylulmood4830
    @eylulmood48302 жыл бұрын

    please sir is it possible to join all the blocks together again?

  • @muhamadilhamajivachroni9885
    @muhamadilhamajivachroni98852 жыл бұрын

    Hi sir How about Binarized Statistical Image features? BSIF work based on learnt from a training set of natural image patches by maximizing the statistical independence of the filter responses. I hope you can make video about it. Thankyou

  • @deepi8787
    @deepi87872 жыл бұрын

    Is that possible to train an unet without generating its corresponding mask ?

  • @منةالرحمن
    @منةالرحمن3 жыл бұрын

    hi sir opening a tif file called this error !!! """TiffPage 0: requires the 'imagecodecs' package"""

  • @anjalichandra5249
    @anjalichandra52493 жыл бұрын

    sir can we use for classification also

  • @madanparajuli9080
    @madanparajuli90802 жыл бұрын

    Does anyone knows how to deal with '.svs' file for the similar task done in this video?

  • @eylulmood4830
    @eylulmood48302 жыл бұрын

    how can I merge the patches after that

  • @samjut3718
    @samjut37182 жыл бұрын

    My images cover the polygons of marginal lands and non-marginal lands. What I want to do is to use U-Net to classify and identify marginal lands from non-marginal lands. Thank you

  • @Asadkhan-nz6qm
    @Asadkhan-nz6qm2 жыл бұрын

    Thank you, Sir, for this video, Sir I have a question can you please help me in this regard. I don't have any masks for my dataset. How do I generate masks for my problem?

  • @DigitalSreeni

    @DigitalSreeni

    2 жыл бұрын

    Please check my videos on the topic of image annotation. I recently published them and I believe I named them, 'Labeling images using....'.

  • @XX-vu5jo
    @XX-vu5jo3 жыл бұрын

    Sreeni do you accept research collaborations?

  • @shankargonti8609
    @shankargonti86093 жыл бұрын

    I waiting for a long time thanks to you sir. small request I not able to find the code file sir.

  • @AyadEKorial
    @AyadEKorial3 жыл бұрын

    Thanks 🌷, but I have question, is this considered as augmentation and increasing the dataset size? Or just for make manipulation easy? Thanks again 🌸

  • @DigitalSreeni

    @DigitalSreeni

    3 жыл бұрын

    This is not augmentation as you are not transforming data to create new data. This is also not increasing the dataset size as you are working with the same data. This is just data pre-processing where you are cutting down the size of each numpy array to ensure they fit your memory. Please remember that for each batch of images you are extracting many filtered images and store in memory. This means you cannot just work with a bunch of 1kx1k images. Example calculation for a batch size 16 images with float32 values. 128x128x3 image - 3MB Same image with 64 filers: 64MB with 128 filters: 128MB In reality, you have many such filters in a deep learning network. Now, let us look at a batch (16) of 1024x1024x3 images - 192MB Same image with 64 filers: 4GB with 128 filters: 8GB How about 1024x1024x3 image with a batch size of 1: 1 image - 12MB 64 filters: 256MB 128 filters: 0.5GB We do not have a large amount of memory to handle these large images during training. Therefore, you need to crop them into smaller sizes that we can handle. PS: I used this image size calculator. svi.nl/ImageSizeCalculator

  • @AyadEKorial

    @AyadEKorial

    3 жыл бұрын

    @@DigitalSreeni Awesome, very clear explanation… thanks.

  • @DigitalSreeni

    @DigitalSreeni

    3 жыл бұрын

    No problem Ayad.

  • @rehmanayounis8429
    @rehmanayounis84293 жыл бұрын

    Hi Sreeni, thanks for this video. But what if we have coloured image having 3 channels. Then its giving me error except if i give patches = patchify(np.array(img2), (256, 256,1), step=256) and then the shape becomes (16, 32, 1, 256, 256, 3) , how to handle it. Thanks

  • @matancadeporco

    @matancadeporco

    3 жыл бұрын

    did u solve this ? i'm trying to use this patchify library to cut some RGB images

  • @marwanabdou1644

    @marwanabdou1644

    3 жыл бұрын

    @@matancadeporco am too ,did u solve it or did u have a another code to do this

  • @johnnysmith6876

    @johnnysmith6876

    2 жыл бұрын

    @@marwanabdou1644 did you find a solution to this?

  • @zeynepsozen2230
    @zeynepsozen22302 жыл бұрын

    Thank you sir

  • @sudeepph9350
    @sudeepph93503 жыл бұрын

    When I try to execute this code it shows the error "Window-Shape is too large " . How to deal with this error??

  • @matancadeporco

    @matancadeporco

    3 жыл бұрын

    when i try to read and RGB image, i get this error, i'm trying to divide RGB images into patches

  • @rizwansuper009
    @rizwansuper0093 жыл бұрын

    Great.. But sir what about third dimension.. If we have different image slices for a 3d object. Then what would be the method..

  • @DigitalSreeni

    @DigitalSreeni

    3 жыл бұрын

    Not sure what you mean by having different image objects in 3rd dimension. If the dataset represents a 3D volume you can define a 3D patch to extract sub volumes. If the dataset represents a 2D stack where you have a stack of different 2D images you need to extract 2D patches. Same rule applies for multispectral images.

  • @somayehseifi8269
    @somayehseifi8269 Жыл бұрын

    Hi, Thank you for your video. I have a question: if i open the image using the PIL library, patchify give me an error. it seems it works with the image.shape which is not defined in PIL library. what should I do if I want to open an image with PIL rather than cv2. and I want to know how can we use these patches in pytorch.

  • @DigitalSreeni

    @DigitalSreeni

    Жыл бұрын

    When you use PIL to open an image, it opens it as an object. You need to convert it to a numpy array. from PIL import Image import numpy as np # Open the image using PIL image = Image.open("image_file.jpg") # Convert the image to a NumPy array image_array = np.array(image)

  • @geospatial90

    @geospatial90

    11 ай бұрын

    When I run this code to my landsat data with 6 bands the results showed an 'window_shape' is too large.. sir, can you please tell me a solution

  • @sivamoorthythilandj9897
    @sivamoorthythilandj98972 жыл бұрын

    sir how to patch using opencv

  • @wasiurrahaman7242
    @wasiurrahaman7242 Жыл бұрын

    Sir if you have multi spectral image with have more than 8 bands then what to do

  • @DigitalSreeni

    @DigitalSreeni

    Жыл бұрын

    They are just like RGB images except in RGB images you have 3 channels (bands) and in multispectral images you have multiple. So instead of using (256 x 256) you will be using (256 x 256 x n) where n is the number of bands.

  • @hridaanshugusain3102
    @hridaanshugusain3102 Жыл бұрын

    How would you do this with RGB images? Thanks

  • @DigitalSreeni

    @DigitalSreeni

    Жыл бұрын

    No difference, same process, except your patch size would be 256x256x3 instead of 256x256

  • @computingyolo5545
    @computingyolo55453 жыл бұрын

    Hi Professor, the coding returns me error ValueError: `window_shape` is too large Which value to be modified? Hope to hear back, all the best

  • @DigitalSreeni

    @DigitalSreeni

    3 жыл бұрын

    It says window shape is too large, please make sure it is not larger than your image itself.

  • @matancadeporco

    @matancadeporco

    3 жыл бұрын

    when i try to divide RGB patches, i get this error... did u solve it?

  • @yifeipei3049

    @yifeipei3049

    2 жыл бұрын

    You need to check the image size. If the image size is less than window shape, it will throw this error.

  • @INSIDERSTUDIO

    @INSIDERSTUDIO

    Жыл бұрын

    @@yifeipei3049 how decrease window shape

  • @tomcat5841
    @tomcat5841 Жыл бұрын

    Hi, how should I use patchify for colored images 256*256*3 images needs to merged to for larger image.

  • @DigitalSreeni

    @DigitalSreeni

    Жыл бұрын

    For multichannel or multidimensional images, your patch size needs to be defined accordingly. For color images, patch size would be something like 64x64x3, instead of just 64x64 that we use to define greyscale images. Similarly, for 3D images, patch size can be 64x64x64. Same rules apply when you are unpatchifying.

  • @tomcat5841

    @tomcat5841

    Жыл бұрын

    @@DigitalSreeni thanks for the response shreeni, I am currently working on this in my company on orthophotos.I am planning to use this.

  • @shubhangigosavi1296
    @shubhangigosavi1296 Жыл бұрын

    While extracting image patches from RGB images, the resolution is affected drastically. What do you think can be done? Kindly guide

  • @DigitalSreeni

    @DigitalSreeni

    Жыл бұрын

    I am not sure what you mean by the resolution getting affected drastically. Patchify breaks your large numpy array into smaller patches. The resolution (pixel values) should not change at all unless you are doing some binning operation. The quality of patches may get affected depending on the format into which you are saving your images. For example, you will lose quality if you save them as JPG. I recommend saving as PNG or tiff.

  • @shubhangigosavi1296

    @shubhangigosavi1296

    Жыл бұрын

    @@DigitalSreeni Ok, Sir. Will try to change the format and check again. Thank you so much.

  • @MrAkhilchibber
    @MrAkhilchibber2 жыл бұрын

    I am getting an error on "patches_image" stating: "ValueError: `window_shape` is too large". By any chance can you help me fix this Error?

  • @DigitalSreeni

    @DigitalSreeni

    2 жыл бұрын

    Sounds like you are trying to divide your image into a patch size that is larger than your image itself.

  • @MrAkhilchibber

    @MrAkhilchibber

    2 жыл бұрын

    @@DigitalSreeni I was trying to Prepare Patch of my Satellite Imagery. Seems like this code would not be feasible for Satellite Imagery?

  • @DigitalSreeni

    @DigitalSreeni

    2 жыл бұрын

    Why not? The method from this video does not care about your application, it just takes your images (numpy arrays) and divides them into patches. If your image is 1024x1024 and you want to divide it into patches of 256x256, this process helps. But if your image is 1024x1024 and you are trying to divide into patches of 2048x2048, it does not make sense as you are defining a patch larger than your image itself. This is the error you are getting.

  • @jocelynw6360
    @jocelynw63602 жыл бұрын

    Sir i am new to image processing.. I am following your videos, I want to do image segmentation on lungs CXR so I download some image from kaggle but I doesn't contain mask image, so can sir help me on how to extract mask for the images I get.. I really need help sir

  • @DigitalSreeni

    @DigitalSreeni

    2 жыл бұрын

    Mask is the ground truth and for that you need expert annotation. If you are an expert in the field you can draw your own annotations using software that is designed for deep learning annotations. I use www.apeer.com because this is what my team develops. If you are not an expert in the field, you need to find datasets with annotation.

  • @jocelynw6360

    @jocelynw6360

    2 жыл бұрын

    @@DigitalSreeni okay.. Thank you sir for the suggestion.. But will it be possible to mask using code

  • @amirhamza5497
    @amirhamza5497 Жыл бұрын

    I have a question. I want to detect pores in concrete. The image is taken, processed and presence of pores is detected. How do you go about that? Much appreciated. Thanks in advance. I'm really looking for a nice, fruitful reply.

  • @matancadeporco
    @matancadeporco3 жыл бұрын

    hi sir, how can i do this for RGB images?

  • @yifeipei3049

    @yifeipei3049

    2 жыл бұрын

    Just add another dimension for the patchify box, e.g., (256, 256, 3).

  • @abdulrahimshihabuddin1119

    @abdulrahimshihabuddin1119

    2 жыл бұрын

    @@yifeipei3049 I don't have any masks for my dataset. How do I generate masks for my problem?

  • @yifeipei5484

    @yifeipei5484

    2 жыл бұрын

    @@abdulrahimshihabuddin1119 What do you mean "mask"?

  • @abdulrahimshihabuddin1119

    @abdulrahimshihabuddin1119

    2 жыл бұрын

    Yifei Pei don't we have to generate segmented masks for training Unet ? I have the images in my hand. And I know the location of ROI I need to obtain a segmented mask for . So what should I do?

  • @yifeipei5484

    @yifeipei5484

    2 жыл бұрын

    @@abdulrahimshihabuddin1119 No, U-Net is just a CNN architecture. If your project is not object detection, you don't need the masks. If your project is related to object detection, you have to use some softwares to label the images and save the masks.

  • @nedaazarmehr
    @nedaazarmehr2 жыл бұрын

    This doesn't work for RGB images.

  • @DigitalSreeni

    @DigitalSreeni

    2 жыл бұрын

    Yes, it does. I have used it in many of my tutorials, for example this one: kzread.info/dash/bejne/nKqOz5qLdamYe7w.html

  • @takfarines5522
    @takfarines55222 жыл бұрын

    Thank you sir, can you please share the code?

  • @DigitalSreeni

    @DigitalSreeni

    2 жыл бұрын

    All my code can be found on my GitHub account. Please look at the video description for the link.

  • @ghazalkz4540
    @ghazalkz4540 Жыл бұрын

    thank you sir

Келесі