logo
down
shadow

Edge Detection code for BufferedImage


Edge Detection code for BufferedImage

By : jckhmmr
Date : November 22 2020, 10:48 AM
Hope this helps For anyone interested , i solved this problem with the use of a Stack.
pre-populate the stack with the order of directions to take. Start moving in a direction. if it can move direction is popped from stack else Hit a border push that direction to the stack add The border to the Set of borders if border is already in set break loop else turn 90 degree relative to the direction
code :


Share : facebook icon twitter icon
Edge Detection method better than Canny Edge detection

Edge Detection method better than Canny Edge detection


By : Ne1roN
Date : March 29 2020, 07:55 AM
wish of those help There are different types of "edges", it depends on your task. Have a look at the recent paper "Which edges matters?" from ICCV-2013, with comparison of several methods:
ultrametric contour map - "Contour Detection and Hierarchical Image Segmentation" by P. Arbelaez, M. Maire, C. Fowlkes, and J. Malik - best results in comparison above. normalized cuts - "Normalized cuts and image segmentation" by J. Shi and J. Malik. mean shift - "Mean shift: A robust approach toward feature space analysis" by D. Comanicu and P. Meer. Felzenszwalb and Huttenlocher approach - "Efficient graph-based image segmentation" by Felzenszwalb and Huttenlocher. BiCE - "Binary coherent edge descriptors" by C. L. Zitnick. N4-Fields - "N4-Fields: Neural Network Nearest Neighbor Fields for Image Transforms" by Ganin et.al RDS - "Learning relaxed deep supervision for better edge detection" by Liu and Lew COB - "Convolutional Oriented Boundaries" by Maninis et.al.
Why does my Sobel edge detection code not work?

Why does my Sobel edge detection code not work?


By : Riccardo Drudi
Date : March 29 2020, 07:55 AM
help you fix your problem Finally figured it out. I shouldn't have been modifying the array in place because it obviously changes the values that are computed in subsequent applications of the filter. This works:
code :
...
new_data = np.zeros(data.shape)
center = offset = 1
for i in range(offset, new_data.shape[0]-offset):
    for j in range(offset, new_data.shape[1]-offset):
        X = data[i-offset:i+offset+1, j-offset:j+offset+1]
        new_data[i, j] = apply(X)
...
Sobel edge detection with BufferedImage.TYPE_BYTE_BINARY as output

Sobel edge detection with BufferedImage.TYPE_BYTE_BINARY as output


By : user7602392
Date : March 29 2020, 07:55 AM
This might help you According to the response in the comment, it should be sufficient to convert the grayscale image that is computed by the edge detection into an image of type TYPE_BYTE_BINARY.
The following is a MCVE that loads the grayscale image that was linked to in the question (containing the edge detection result), and converts it into a binary image.
code :
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.GridLayout;
import java.awt.image.BufferedImage;
import java.net.URL;

import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSlider;
import javax.swing.SwingUtilities;

public class ImageToBinary
{
    public static void main(String[] args) throws Exception
    {
        BufferedImage input = 
            ImageIO.read(new URL("https://i.stack.imgur.com/jvOan.png"));        

        BufferedImage output = convertToBinary(input, 10);

        SwingUtilities.invokeLater(() -> createAndShowGui(input, output));
    }

    private static void createAndShowGui(
        BufferedImage input, BufferedImage output)
    {
        JFrame f = new JFrame();
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        JPanel p = new JPanel(new GridLayout(1,2));
        JLabel outputLabel = new JLabel(new ImageIcon(output));
        p.add(new JLabel(new ImageIcon(input)));    
        p.add(outputLabel);
        f.getContentPane().setLayout(new BorderLayout());
        f.getContentPane().add(p, BorderLayout.NORTH);   

        JSlider slider = new JSlider(0, 256, 10);
        slider.addChangeListener(e -> 
        {
            int threshold = slider.getValue();
            BufferedImage newOutput = convertToBinary(input, threshold);
            outputLabel.setIcon(new ImageIcon(newOutput));
        });

        f.getContentPane().add(slider, BorderLayout.SOUTH);
        f.pack();

        f.setLocationRelativeTo(null);
        f.setVisible(true);

    }

    private static BufferedImage convertToBinary(
        BufferedImage input, int threshold)
    {
        int w = input.getWidth();
        int h = input.getHeight();
        BufferedImage output = new BufferedImage(
            w, h, BufferedImage.TYPE_BYTE_BINARY);

        int blackRgb = Color.BLACK.getRGB();
        int whiteRgb = Color.WHITE.getRGB();

        for (int y = 0; y < h; y++)
        {
            for (int x = 0; x < w; x++)
            {

                int rgb = input.getRGB(x, y);
                int r = (rgb >> 16) & 0xFF;
                int g = (rgb >> 8) & 0xFF;
                int b = (rgb) & 0xFF;
                int gray = (int) (0.2126 * r + 0.7152 * g + 0.0722 * b);
                if (gray >= threshold)
                {
                    output.setRGB(x, y, whiteRgb);
                }
                else
                {
                    output.setRGB(x, y, blackRgb);
                }
            }
        }
        return output;
    }        

}
What is the OpenCv equivalent of this Matlab code for Sobel edge detection?

What is the OpenCv equivalent of this Matlab code for Sobel edge detection?


By : D.Alex
Date : March 29 2020, 07:55 AM
seems to work fine The MATLAB implementation of the sobel edge detection isn't visible so we can only guess exactly what is happening. The only hint we get is from the documentation on edge states that when the 'sobel' option is used then
code :
import cv2
import numpy as np
import scipy.ndimage.filters

gray_image = cv2.imread('cell.png', cv2.IMREAD_GRAYSCALE).astype(dtype=np.float32)

def orientated_non_max_suppression(mag, ang):
    ang_quant = np.round(ang / (np.pi/4)) % 4
    winE = np.array([[0, 0, 0],
                     [1, 1, 1],
                     [0, 0, 0]])
    winSE = np.array([[1, 0, 0],
                      [0, 1, 0],
                      [0, 0, 1]])
    winS = np.array([[0, 1, 0],
                     [0, 1, 0],
                     [0, 1, 0]])
    winSW = np.array([[0, 0, 1],
                      [0, 1, 0],
                      [1, 0, 0]])

    magE = non_max_suppression(mag, winE)
    magSE = non_max_suppression(mag, winSE)
    magS = non_max_suppression(mag, winS)
    magSW = non_max_suppression(mag, winSW)

    mag[ang_quant == 0] = magE[ang_quant == 0]
    mag[ang_quant == 1] = magSE[ang_quant == 1]
    mag[ang_quant == 2] = magS[ang_quant == 2]
    mag[ang_quant == 3] = magSW[ang_quant == 3]
    return mag

def non_max_suppression(data, win):
    data_max = scipy.ndimage.filters.maximum_filter(data, footprint=win, mode='constant')
    data_max[data != data_max] = 0
    return data_max

# compute sobel response
sobelx = cv2.Sobel(gray_image, cv2.CV_32F, 1, 0, ksize=3)
sobely = cv2.Sobel(gray_image, cv2.CV_32F, 0, 1, ksize=3)
mag = np.hypot(sobelx, sobely)
ang = np.arctan2(sobely, sobelx)
# threshold
fudgefactor = 0.5
threshold = 4 * fudgefactor * np.mean(mag)
mag[mag < threshold] = 0
# non-maximal suppression
mag = orientated_non_max_suppression(mag, ang)
# alternative but doesn't consider gradient direction
# mag = skimage.morphology.thin(mag.astype(np.bool)).astype(np.float32)

# create mask
mag[mag > 0] = 255
mag = mag.astype(np.uint8)
How can I colour my sketch using pen tool within the limited edge boundaries using sobel edge detection/canny edge detec

How can I colour my sketch using pen tool within the limited edge boundaries using sobel edge detection/canny edge detec


By : user5927815
Date : March 29 2020, 07:55 AM
Any of those help Hey Pradip you are looking for floodfill algorithm to be exact it will solve your problem.
Floodfill Algorithm Brief Explanation -
Related Posts Related Posts :
  • Content autocomplete in spring tool suite 4
  • Super Noob Help ~ MouseEvent/Frame
  • Making one project with dependencies stand-alone in Eclipse (Java)
  • Jsoup- getting certain attributes from website
  • MongoDB, how to make a link between collections with JAVA code
  • Overriding an abstract method means class abstract class or not in java?
  • Bukkit teleport - nullPointerException
  • How to check if a Float variable is negative in java
  • Servlet: Cannot forward after response has been committed
  • sql query to select a specific cell in excel
  • How to make new picture when mouse dragged in java
  • Use Constants interface in GWT Project
  • Setting size of a JPanel in GroupLayout
  • Construct a map from two equal size arrays
  • Implementing Read-Write Locks with Double-Checked Locking
  • Disable NO_BUTTON from JOptionPane Java if a condition is true
  • UDP multiple socket
  • Android Threading: This Handler class should be static or leaks might occur
  • The type org.openqa.selenium.firefox.FirefoxDriver is not accessible
  • Limitations (drawbacks) of java programming language?
  • Error: ')' expected Error: illegal start of expression
  • TableRowSorter use LookAndFeel of TableHeader, but own Comparator
  • Difference between @GeneratedValue and @GenericGenerator
  • Design Scenario: Smartphone class and will have derived classes like IPhone,AndroidPhone,WindowsMobilePhone can be even
  • Java date parsing without separators?
  • how to map an array of custom type from postgres to java using hibernate
  • Why hibernate always call "update" statement after using "select" statement in MySQL?
  • An interview topic: What can go wrong with this code?
  • How do I regex remove whitespace and newlines from a text, except for when they are in a json's string?
  • How to turn off Preferences > Compiles > User External Build?
  • how to convert arraylist to string array with all items in double quote
  • PMD+Maven+JAVA Error:: Can't find resource rulesets/comments.xml. Make sure the resource is a valid file or URL or is on
  • How to extend AbstractScheduledService.Scheduler
  • Primefaces tabview: set Active Index after some counting
  • Need help in Regex to exclude splitting string within "
  • Get header from HttpUrlConnection object
  • encoding xlsx as base64 and send it as an attachment
  • How to acess HttpServletRequest in Jaas login module in Tomcat
  • How to implement a basic pointer
  • Java Swing Exit Icon?
  • Why onNext has no effect
  • IntelliJ Idea 2018.2 no option for importing gradle project
  • Remove a negative element from an array w/o array.copy
  • Could this prevent overflow in Java?
  • In Java Swing, can I receive Caret events in real time?
  • I need help not using brute force when using JFrames and DrawWindows
  • How do I refactor ArrayList<MyClass> into MyClassLIst?
  • My program keeps saying that the method cannot be resolved
  • BubbleSort -my code returns random addresses
  • JavaFX components inside HTML?
  • Character in Java game not responding
  • Working around access denied in a FileWalking Tree in Java7
  • How to avoid if/else when using multple suppliers?
  • How to pass object from table cell editor to Table Model?
  • Paypal Sandbox payment state pending
  • sejda-console.bat passing parameters with spaces
  • Multiple Consumers Spring Kafka
  • Bitbucket pipeline: environmental variables in build.gradle file not recognized
  • Java static enum method to return a default enum value
  • What is the complexity of empty for loop?
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org