How Do I Convert and Image To A Line/Array

I am trying to create a software to covert MRI images into a 3D model and i am trying to create a line body or basic main body umage that i can use to stack and then connect in a mesh whcih i will convert into a 3D model. I have sharpened the images and reduced noise, i have it in grayscale but how do i get it down into a basic image or linbe so i can plot it. has anyone done somthing similar? Do you have a solution?

5 comentarios

Harsh
Harsh el 30 de Jul. de 2024
Hey @Thomas, do you need the image in the form of a 1D array, or are you just looking for a way to plot it?
"Basic Image"
Also, could you explain a bit further what is meant by a "basic image"? Are there specific attributes or requirements that define it, such as resolution, color depth, format, or any particular content or style?
Thomas
Thomas el 30 de Jul. de 2024
I am looking to convert this "basic Image" (defined by it being 1 singular black and white body in the centre of the image with high sharpness and clarity) to a 2D arrary that can be plotted on the graph as a slice of a mesh. I intend to combine the images using a Cat() function and then meshing it. Do you know how i can solve this?
DGM
DGM el 30 de Jul. de 2024
If it's applicable, bwboundaries() can be used to resolve the boundary of an object in a binary image and express it as an ordered sequence of points in image coordinates (i.e. the locations of the boundary pixels). Optimally reducing the complexity of the path may be one challenge. Expanding that into a 3D mesh is another.
I'm not terribly familiar with how either of those two tasks would best be performed, but if you provide a minimal example of the data, that might help make it easier for someone to attempt a solution.
Thomas
Thomas el 31 de Jul. de 2024
I have used bwboundries() and come up with an odd code after having AI debug it. I have created a new post about the project that countains the code that is broken (it is about 82 lines). Thank you for your help
Umar
Umar el 31 de Jul. de 2024

@Thomas,

The AI is written by human beings and trust me if humans created it, it will always have bugs in it. However, @DGM is our technical expert and has helped me on several occasions by helping me out with complex tasks. He is highly respected and knowledgeable individual. We heavily rely on his expertise. However, I tried my best to help resolve your problem. So, first I created the denoiseMRI function in the code snippet which is designed to denoise MRI images by applying median filtering. It first checks if the input image is grayscale; if not, it converts it to grayscale. The function then uses a 3x3 median filter to denoise the image. The subsequent code loads an MRI image, preprocesses it using the denoiseMRI function, displays the processed image, converts it to a binary image, performs edge detection using the Canny method, and generates a 3D mesh representation of the detected edges. Here is script code along with function.

%function denoiseMRI implementation

function denoised_image = denoiseMRI(input_image)

    % Check if the input image is grayscale
    if ndims(input_image) == 2
        % Input image is already two-dimensional (grayscale)
        denoised_image = medfilt2(input_image, [3 3]);
    else
        % Convert RGB image to grayscale
        gray_image = rgb2gray(input_image);
        % Apply median filtering to the grayscale image
        denoised_image = medfilt2(gray_image, [3 3]);
    end

end

%script

% Load the MRI image

mri_image = imread('/MATLAB Drive/IMG_7242.JPG');

% Preprocess the image using the updated denoiseMRI function

processed_image = denoiseMRI(mri_image);

% Display the processed image

imshow(processed_image);

% Convert the processed image to a binary image

binary_image = imbinarize(processed_image);

% Perform edge detection to extract the main body or lines

edge_image = edge(binary_image, 'Canny');

% Create a mesh from the edge image

[X, Y] = meshgrid(1:size(edge_image, 2), 1:size(edge_image, 1));

Z = zeros(size(edge_image));

 % Convert 'edge_image' to a numeric array

edge_image_numeric = double(edge_image);

% Plot the 3D model with the corrected 'CData'

figure;

surf(X, Y, Z, 'CData', edge_image_numeric, 'EdgeColor', 'none');

colormap(gray);

axis equal;

view(3);

Please see attached plot.

I did encounter problems while implementing this code and after some debugging, it was resolved. Hope, this will help resolve your problem.

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Convert Image Type en Centro de ayuda y File Exchange.

Productos

Versión

R2024a

Etiquetas

Preguntada:

el 30 de Jul. de 2024

Comentada:

el 31 de Jul. de 2024

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by