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

แชร์
ฝัง

ความคิดเห็น • 96

  • @chrisber
    @chrisber 2 ปีที่แล้ว +2

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

  • @louis-philip
    @louis-philip ปีที่แล้ว

    Love the way you explain everything man, thank you!

  • @aminulhuq6668
    @aminulhuq6668 ปีที่แล้ว +1

    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.

  • @Sean-yg3tr
    @Sean-yg3tr 2 หลายเดือนก่อน

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

  • @karangadgil9847
    @karangadgil9847 2 ปีที่แล้ว

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

  • @niluparupasinghe6345
    @niluparupasinghe6345 3 ปีที่แล้ว

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

  • @bSariturk
    @bSariturk 3 ปีที่แล้ว

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

  • @v.lobanov
    @v.lobanov 3 ปีที่แล้ว +9

    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?

  • @chouchou2445
    @chouchou2445 3 ปีที่แล้ว +1

    Great always the best 💖

  • @lennertantson8050
    @lennertantson8050 2 ปีที่แล้ว +1

    Just what I needed, thank you !

  • @sbsyr5555
    @sbsyr5555 3 ปีที่แล้ว

    Thank you for sharing new one...

  • @RedShipsofSpainAgain
    @RedShipsofSpainAgain 2 ปีที่แล้ว +4

    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

  • @hebayousif88
    @hebayousif88 2 ปีที่แล้ว +2

    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?

  • @mohammadkarami8984
    @mohammadkarami8984 3 ปีที่แล้ว

    Thank you very much for nice and concise video

  • @samjut3718
    @samjut3718 2 ปีที่แล้ว

    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

  • @alele5410
    @alele5410 ปีที่แล้ว +1

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

  • @bediosoro7786
    @bediosoro7786 3 ปีที่แล้ว +1

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

  • @zzmirror4294
    @zzmirror4294 2 ปีที่แล้ว

    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 ?

  • @zeynepsozen2230
    @zeynepsozen2230 2 ปีที่แล้ว

    Thank you sir

  • @fuegopuro5933
    @fuegopuro5933 3 ปีที่แล้ว

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

  • @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?

  • @hungchu7840
    @hungchu7840 3 ปีที่แล้ว

    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

  • @navinbondade5365
    @navinbondade5365 3 ปีที่แล้ว

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

  • @eylulmood4830
    @eylulmood4830 2 ปีที่แล้ว +1

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

  • @muhamadilhamajivachroni9885
    @muhamadilhamajivachroni9885 2 ปีที่แล้ว

    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

  • @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)?

  • @AyadEKorial
    @AyadEKorial 2 ปีที่แล้ว +1

    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  2 ปีที่แล้ว +2

      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 2 ปีที่แล้ว +1

      @@DigitalSreeni Awesome, very clear explanation… thanks.

    • @DigitalSreeni
      @DigitalSreeni  2 ปีที่แล้ว +1

      No problem Ayad.

  • @ankushjamthikar9780
    @ankushjamthikar9780 2 ปีที่แล้ว

    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?

  • @anjalichandra5249
    @anjalichandra5249 3 ปีที่แล้ว

    sir can we use for classification also

  • @deepi8787
    @deepi8787 2 ปีที่แล้ว

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

  • @eylulmood4830
    @eylulmood4830 2 ปีที่แล้ว +1

    how can I merge the patches after that

  • @XX-vu5jo
    @XX-vu5jo 3 ปีที่แล้ว

    Sreeni do you accept research collaborations?

  • @madanparajuli9080
    @madanparajuli9080 2 ปีที่แล้ว

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

  • @chouchou2445
    @chouchou2445 3 ปีที่แล้ว

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

  • @Iamanandraj
    @Iamanandraj 2 ปีที่แล้ว

    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

  • @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?

  • @samjut3718
    @samjut3718 2 ปีที่แล้ว +1

    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-nz6qm 2 ปีที่แล้ว

    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....'.

  • @rehmanayounis8429
    @rehmanayounis8429 3 ปีที่แล้ว

    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 2 ปีที่แล้ว

      @@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?

  • @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.

  • @rizwansuper009
    @rizwansuper009 3 ปีที่แล้ว

    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 ปีที่แล้ว +1

      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.

  • @shankargonti8609
    @shankargonti8609 3 ปีที่แล้ว

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

  • @sudeepph9350
    @sudeepph9350 3 ปีที่แล้ว

    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 ปีที่แล้ว +1

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

  • @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 10 หลายเดือนก่อน

      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
    @sivamoorthythilandj9897 2 ปีที่แล้ว

    sir how to patch using opencv

  • @tomcat5841
    @tomcat5841 ปีที่แล้ว

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

    • @DigitalSreeni
      @DigitalSreeni  ปีที่แล้ว +2

      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.

  • @computingyolo5545
    @computingyolo5545 3 ปีที่แล้ว

    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 ปีที่แล้ว +1

      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

  • @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

  • @jocelynw6360
    @jocelynw6360 2 ปีที่แล้ว

    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

  • @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
    @MrAkhilchibber 2 ปีที่แล้ว

    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.

  • @matancadeporco
    @matancadeporco 3 ปีที่แล้ว

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

    • @yifeipei3049
      @yifeipei3049 2 ปีที่แล้ว +1

      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.

  • @takfarines5522
    @takfarines5522 2 ปีที่แล้ว

    Thank you sir, can you please share the code?

    • @DigitalSreeni
      @DigitalSreeni  2 ปีที่แล้ว +1

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

  • @nedaazarmehr
    @nedaazarmehr 2 ปีที่แล้ว

    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: th-cam.com/video/jvZm8REF2KY/w-d-xo.html

  • @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.

  • @ghazalkz4540
    @ghazalkz4540 ปีที่แล้ว

    thank you sir