I have an image and its centroid and I plotted lines passing through the centroid. And I wonder if it would be possible to represent separately each of the parts that are on either side of the line to work with them separately. You can get to the representation of each of
Sie verfolgen jetzt diese Frage
- Aktualisierungen können Sie in Ihrem Feed verfolgter Inhalte sehen.
- Je nach Ihren Kommunikationseinstellungen können Sie auch E-Mails erhalten.
dividing an image into two with the aid of a line
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
hello! I have not much experience with matlab and I have a question! I wonder if drawing a line on an image, the image can be divided into two parts from that line and represent each of them separately! thank you very much to all
Akzeptierte Antwort
elena
am 30 Apr. 2013
15 Kommentare
Image Analyst
am 30 Apr. 2013
⋮
-
Verknüpfen
Direkter Link zu diesem Kommentar
How many lines? What angles are they at? Please upload a screenshot of your image with the line overlaid onto it to snag.gy. And please answer the questions I asked in my comment above.
elena
am 1 Mai 2013
⋮
-
Verknüpfen
Direkter Link zu diesem Kommentar
the image is melanoma, but it serves any image. I want to draw a line passing through the centroid and I'm spinning at different angles, so the angle is not important. Would be drawing a line on any image, the image can be split through that line. Are not any curved line. What is snag.gy? instead of dividing the image into two parts, I also used two different matrices store the data of each of the parties, but neither is how. Can you help me on this?
Image Analyst
am 1 Mai 2013
⋮
-
Verknüpfen
Direkter Link zu diesem Kommentar
Bearbeitet: Image Analyst
am 1 Mai 2013
An image has to be rectangular. What do you want to have in the space where your quadrilateral image is not present? Just black?
http://snag.gy is a web site where you can just paste your screenshot. Hit print screen, then go to snag.gy and type control-v. Then tell us the URL.
And you never answered my question above as to what it means "to plot" the image. Please answer.
elena
am 2 Mai 2013
⋮
-
Verknüpfen
Direkter Link zu diesem Kommentar
when I said I meant plot the image to draw or represent the area of the image that was on the side of the line. But now I would have to be able to save the data in a matrix. I mean, I have an image and a line running through it, well, I would like to save on two different data matrices that are on each side of the line, to be able to work well with them separately, not necessarily convert the other values to black. this is my image with a line (which could be any other) http://snag.gy/FyszT.jpg Now I would like to know how to save on two different matrices each of the areas separated by the line. I tried with a for loop but I only keep the last value, not how to save all settings. Do not know if I'm explaining it right. I appreciate your help.
elena
am 2 Mai 2013
⋮
-
Verknüpfen
Direkter Link zu diesem Kommentar
I had not seen the pictures that you sent me, is exactly what I'm looking for.
Image Analyst
am 2 Mai 2013
⋮
-
Verknüpfen
Direkter Link zu diesem Kommentar
Then just scroll up. I didn't sent them to you - I posted them here. Extend your line to the edges of the image, figure out what the coordinates are, then blacken out above or below that, then use imcrop and imwrite for each half.
elena
am 2 Mai 2013
⋮
-
Verknüpfen
Direkter Link zu diesem Kommentar
I did not understand very well what I have to do. I try to work with the command imcrop, but the only thing I'm able to cut are rectangles, not how to do to crop an image regardless of which direction this the line. Another thing is that to use the command imcrop need not take the points that demarcate the cropped image manually, but I have to do everything programmatically. How I can do? thanks for your help
Image Analyst
am 2 Mai 2013
⋮
-
Verknüpfen
Direkter Link zu diesem Kommentar
An image must stay rectangular. But you can find the bounding box of your polygon. If you want to analyze within the polygon, then you have to get a binary image of it and use regionprops.
Have you gone through and understood my Image Segmentation Tutorial yet? http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862
elena
am 2 Mai 2013
⋮
-
Verknüpfen
Direkter Link zu diesem Kommentar
I've been watching the demo code for segmentation of the image and I think more or less I understand everything. But I've tried to label the components of my image and I get only one, the whole melanoma, ignores the line to split. So I have not been very clear idea of how to do it. I'm sorry but it is very difficult for me.
Image Analyst
am 2 Mai 2013
⋮
-
Verknüpfen
Direkter Link zu diesem Kommentar
Bearbeitet: Image Analyst
am 2 Mai 2013
Maybe I'll have time later to help you if you upload the original image plus the binary mask that goes with it. No promises though. But what do you want to know about it? The intensity on each side of the line? The length of the line inside the lesion for each angle? Something else?
elena
am 3 Mai 2013
⋮
-
Verknüpfen
Direkter Link zu diesem Kommentar
I just want to divide it into two parts so to calculate the centroid of each, but I think I know how to do without having to divide them. I try to do, and if I can not resolve I will ask again. Thank you very much for your help.
Image Analyst
am 3 Mai 2013
⋮
-
Verknüpfen
Direkter Link zu diesem Kommentar
Why do you want the centroid on each side? Well, anyway, here is the code to do that. You will have to change the folder name (where you stored the image because it is not the same folder as where I stored in on my computer), and if you're starting from the original binary image, you can cut out the part where I read in the figure you uploaded and cropped it.
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
imtool close all; % Close all imtool figures if you have the Image Processing Toolbox.
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 20;
% Check that user has the Image Processing Toolbox installed.
hasIPT = license('test', 'image_toolbox');
if ~hasIPT
% User does not have the toolbox installed.
message = sprintf('Sorry, but you do not seem to have the Image Processing Toolbox.\nDo you want to try to continue anyway?');
reply = questdlg(message, 'Toolbox missing', 'Yes', 'No', 'Yes');
if strcmpi(reply, 'No')
% User said No, so exit.
return;
end
end
% Read in a standard MATLAB gray scale demo image.
folder = 'C:\Users\Elena\Documents\Temporary';
baseFileName = 'FyszT.jpg';
% Get the full filename, with path prepended.
fullFileName = fullfile(folder, baseFileName);
% Check if file exists.
if ~exist(fullFileName, 'file')
% File doesn't exist -- didn't find it there. Check the search path for it.
fullFileName = baseFileName; % No path this time.
if ~exist(fullFileName, 'file')
% Still didn't find it. Alert user.
errorMessage = sprintf('Error: %s does not exist in the search path folders.', fullFileName);
uiwait(warndlg(errorMessage));
return;
end
end
grayImage = imread(fullFileName);
% Get the dimensions of the image.
% numberOfColorBands should be = 1.
[rows, columns, numberOfColorBands] = size(grayImage);
if numberOfColorBands > 1
% It's not really gray scale like we expected - it's color.
% Convert it to gray scale by taking only the green channel.
grayImage = grayImage(:, :, 2); % Take green channel.
end
% Display the original gray scale image.
subplot(2, 3, 1);
imshow(grayImage, []);
axis on;
title('Original Grayscale Image', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
% Give a name to the title bar.
set(gcf,'name','Demo by ImageAnalyst','numbertitle','off')
% Crop it
grayImage = imcrop(grayImage, [370, 156, 620, 428]);
subplot(2, 3, 2);
imshow(grayImage, []);
axis on;
title('Cropped Grayscale Image', 'FontSize', fontSize);
% Turn it into a binary image and do a closing to fillin the black line.
binaryImage = imclose(grayImage > 0, true(3));
subplot(2, 3, 3);
imshow(binaryImage, []);
axis on;
title('Binary Image', 'FontSize', fontSize);
% Ask use to draw a line
promptMessage = sprintf('Locate the end points of the line on the upper right image.\nMove to the center of the line (until you get the quad arrows)\nand double click when done');
titleBarCaption = 'Continue?';
button = questdlg(promptMessage, titleBarCaption, 'OK', 'Cancel', 'OK');
if strcmpi(button, 'Cancel')
return;
end
hLine = imline;
position = wait(hLine)
% Create a binary image ("mask") from the ROI object.
lineMask = hLine.createMask();
subplot(2, 3, 4);
imshow(lineMask, []);
axis on;
title('Line Mask', 'FontSize', fontSize);
% Burn the line into the image
binaryImage(lineMask) = false;
subplot(2, 3, 5);
imshow(binaryImage, []);
axis on;
title('Binary Object Split into 2 Parts', 'FontSize', fontSize);
labeledImage = bwlabel(binaryImage, 4); % Label each blob so we can make measurements of it
coloredLabels = label2rgb (labeledImage, 'hsv', 'k', 'shuffle'); % pseudo random color labels
subplot(2, 3, 6);
imagesc(coloredLabels);
axis on;
caption = sprintf('Pseudo colored labels, from label2rgb(),\nwith centroids marked.');
title(caption, 'FontSize', fontSize);
% Get all the blob properties. Can only pass in originalImage in version R2008a and later.
blobMeasurements = regionprops(labeledImage, 'Centroid');
numberOfBlobs = size(blobMeasurements, 1);
hold on;
for blob = 1 : numberOfBlobs
thisCentroid = blobMeasurements(blob).Centroid
plot(thisCentroid(1), thisCentroid(2), 'w+');
end
elena
am 4 Mai 2013
⋮
-
Verknüpfen
Direkter Link zu diesem Kommentar
I've managed to do what I was looking for, but anyway I will consider the code you sent me. Thank you very much for all your help, I really appreciate it.
Elysi Cochin
am 7 Mai 2015
⋮
-
Verknüpfen
Direkter Link zu diesem Kommentar
Bearbeitet: Elysi Cochin
am 7 Mai 2015
what if, i have the (x1,y1) and (x2,y2) points... where to edit the code.... how to get the lineMask please do help sir...
Image Analyst
am 7 Mai 2015
⋮
-
Verknüpfen
Direkter Link zu diesem Kommentar
If you have a large binary blob and you want to burn a line into it, see my attached demo.
Weitere Antworten (1)
Image Analyst
am 29 Apr. 2013
How do you want to handle it if the line starts and stops within the image? Do you want to extend it until it hits the edge of the image? And then take the bounding box of each quadrilateral and zero out parts on the "wrong" side of the line?
6 Kommentare
elena
am 30 Apr. 2013
⋮
-
Verknüpfen
Direkter Link zu diesem Kommentar
I would like to find a function by which after drawing a line with any angle in the picture, you could plot separately each part of the image that is divided by that line. would this be possible? I appreciate your help
Image Analyst
am 30 Apr. 2013
⋮
-
Verknüpfen
Direkter Link zu diesem Kommentar
So you have two quadrilateral-shaped gray scale images. What does it mean to "plot" them? Some kind of line curve that represents what???
Image Analyst
am 1 Mai 2013
⋮
-
Verknüpfen
Direkter Link zu diesem Kommentar
Bearbeitet: Image Analyst
am 1 Mai 2013
Do you mean like this:
so that you save two rectangular images, each with a three to five-sided black region?
sameena pathan
am 21 Mär. 2017
⋮
-
Verknüpfen
Direkter Link zu diesem Kommentar
Hello Sir, Kindly help me in resolving this issue. How to divide a segmented portion of an image into two halves with respect to the major axis of the image? Your Kindness is greatly appreciated
waffle
am 8 Apr. 2017
⋮
-
Verknüpfen
Direkter Link zu diesem Kommentar
can u help me how to do that
Image Analyst
am 8 Apr. 2017
⋮
-
Verknüpfen
Direkter Link zu diesem Kommentar
What information do you have so far? Do you at least have the formula or endpoints of the line? Or do you not even have that? If not, then what do you need to do to get that? Do you need to develop the ENTIRE image segmentation algorithm right from the very start after you call imread()? (I hope not.)
Siehe auch
Kategorien
Mehr zu Specifying Target for Graphics Output finden Sie in Help Center und File Exchange
Tags
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Es ist ein Fehler aufgetreten
Da Änderungen an der Seite vorgenommen wurden, kann diese Aktion nicht abgeschlossen werden. Laden Sie die Seite neu, um sie im aktualisierten Zustand anzuzeigen.
Website auswählen
Wählen Sie eine Website aus, um übersetzte Inhalte (sofern verfügbar) sowie lokale Veranstaltungen und Angebote anzuzeigen. Auf der Grundlage Ihres Standorts empfehlen wir Ihnen die folgende Auswahl: .
Sie können auch eine Website aus der folgenden Liste auswählen:
So erhalten Sie die bestmögliche Leistung auf der Website
Wählen Sie für die bestmögliche Website-Leistung die Website für China (auf Chinesisch oder Englisch). Andere landesspezifische Websites von MathWorks sind für Besuche von Ihrem Standort aus nicht optimiert.
Amerika
- América Latina (Español)
- Canada (English)
- United States (English)
Europa
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asien-Pazifik
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)