def setImage(self,
                 img,
                 autoRange=True,
                 autoLevels=True,
                 levels=None,
                 axes=None,
                 xvals=None,
                 pos=None,
                 scale=None,
                 transform=None,
                 autoHistogramRange=True,
                 contains_plot_info=False):
        """
        Sets a new image

        When changing an image, tries to keep the old z-index

        Changes the wheel-event from zoom-out
        to slice change
        """
        #Saves previous z-index
        previousIndex = self.currentIndex
        is_shown = False
        if self.imageDisp is not None:
            previousShape = self.imageDisp.shape
            is_shown = True

        self.isNewImage = True
        if contains_plot_info:
            super().setImage(img[0, ...], autoRange, autoLevels, levels, axes,
                             xvals, pos, scale, transform, autoHistogramRange)
            self.imageCopy = Imeta.Image(img, True)
        else:
            super().setImage(img, autoRange, autoLevels, levels, axes, xvals,
                             pos, scale, transform, autoHistogramRange)
            self.imageCopy = Imeta.Image(self.imageDisp.copy(), False)
        self.pen_value = np.amax(self.imageDisp) + 1

        #Changes wheel event
        self.ui.roiPlot.setMouseEnabled(True, True)
        self.ui.roiPlot.wheelEvent = self.roi_scroll_bar
        max_t = self.imageDisp.shape[0]
        self.normRgn.setRegion((1, max_t // 2))
        if not is_shown:
            return
        #Shows image at previous z-index if in range
        if previousIndex < self.imageDisp.shape[0]:
            self.setCurrentIndex(previousIndex)
Beispiel #2
0
 def end_preview(self, image, number):
     name = "Preview"
     if name in self.images:
         self.images[name] = Imeta.Image(image)
     else:
         self.add_image(image, name)
     self.choose_image(name, preview=True, autoLevels=False)
Beispiel #3
0
    def add_image(self, image, name, plot_info=False):
        """
        Adds an image to the combobox
        and to the self.images dictionary

        Parameters
        ----------
        image: np.ndarray
            the image
        name: str
            combobox name
        """
        self.mainview.combobox.addItem(name)
        image_with_metadata = Imeta.Image(image, contains_plot_info=plot_info)
        self.images[name] = image_with_metadata
        img_data_name = self.current_name(self.img_data)
        self.metadata[name] = self.metadata[
            img_data_name] if img_data_name in self.metadata else None
    canvas_result = st_canvas(
        stroke_width=20,
        stroke_color="#fff",
        background_color="#000",
        update_streamlit=True,
        height=280,
        width=280,
        drawing_mode="freedraw",
        key="canvas",
    )

if st.button('Get prediction'):
    model = Model()

    # Instantiate an Image object from the handwritten canvas
    image = Image(canvas_result.image_data)

    with col2:
        # Display a h2 title
        st.subheader("What the computer see")
        st.markdown("Your drawing is resized and gray-scaled")

        # Display the transformed image
        if image.array is not None:
            st.image(image.get_streamlit_displayable(), width=280)

    # Check if the user has written something
    if (image.array is not None) and (not image.is_empty()):
        # Get the predicted class
        prediction = model.predict(image.get_prediction_ready())
        stroke_width=8,
        stroke_color="#fff",
        background_color="#000",
        update_streamlit=True,
        height=290,
        width=290,
        drawing_mode="freedraw",
        key="canvas",
    )

# Check if the user has written something
if st.button('Get prediction'):
    model = Model()

    # Instantiate an Image object from the handwritten canvas
    image = Image(canvas_result.image_data)
    # Get the predicted class
    prediction = model.predict(image.get_prediction_ready())
    class_list = ['angel', 'sword', 'airplane', 'camel', 'diamond', 'lion']

    col3, col4 = st.beta_columns(2)

    # Display the digit predicted by the model
    with col3:
        st.subheader("Recognized draw")
        st.markdown("The draw recognized by the model")
        st.markdown(
            f'<p style="font-size: 44px;'
            f'font-weight: bold;'
            f'text-align: center;'
            f'display: flex;'
Beispiel #6
0
col1, col2 = st.beta_columns([6, 4])

# Drawing area
with col1:

    st.subheader("Drawing area")
    st.markdown("Draw something cool, don't make it easy !")
    canvas_result = st_canvas(stroke_width=20,
                              stroke_color="#fff",
                              background_color="#000",
                              update_streamlit=True,
                              drawing_mode="freedraw",
                              key="canvas",
                              width=400)

image = Image(canvas_result.image_data)

with col2:
    st.subheader("This model can recognize...")
    st.markdown("""
    Between 8 different items:
    
     - Banana
     - Axe
     - Spider
     - Hand
     - House
     - Eyeglasses
     - Cup
     - Diamond