How to display a value from a variable into a textbox

if true
% code
global citra
global tampung
I = rgb2gray(citra);
BW = tampung;
BW = im2bw(BW);
s = regionprops(BW, I, {'Centroid','WeightedCentroid'});
numberOfBlobs = size(s, 1);
labelShiftX = -7; %untuk mengkondisikan posisi titik tengah.
titikX = [1 2 3 4];
titikY = [1 2 3 4];
end
hold on
numObj = numel(s);
for k = 1 : numObj
plot(s(k).WeightedCentroid(1), s(k).WeightedCentroid(2), 'r*');
titikX(k)=s(k).WeightedCentroid(1);
plot(s(k).Centroid(1), s(k).Centroid(2), 'bo');
titikY(k)=s(k).WeightedCentroid(2);
end
hold off
Xmtkaki = (titikX(1)-titikX(4));
Ymtkaki = (titikY(1)-titikY(4));
Xmtkika = (titikX(4)-titikX(1));
Ymtkika = (titikY(4)-titikY(1));
Xmtkamu = (titikX(1)-titikX(2));
Ymtkamu = (titikY(1)-titikY(2));
Xmtkimu = (titikX(4)-titikX(2));
Ymtkimu = (titikY(4)-titikY(2));
Xmtkahi = (titikX(1)-titikX(3));
Ymtkahi = (titikY(1)-titikY(3));
Xmtkihi = (titikX(4)-titikX(3));
Ymtkihi = (titikY(4)-titikY(3));
I want to display value from this variable (Xmtkaki, Ymtkaki) to a text box, but i didn't know how to display it.
need u'r help
thanks in advance.

 채택된 답변

Walter Roberson
Walter Roberson 2013년 4월 4일
Let position1 and position2 each be (different) 4-element position vectors reflecting the location and size of the two text boxes. For example, [0 0 .1 .05]
The next two lines only need to be done once, to create the text boxes.
textbox1 = uicontrol('Style', 'text', 'Units', 'norm', 'Position', position1);
textbox2 = uicontrol('Style', 'text', 'Units', 'norm', 'Position', position2);
Then, each time you want to update the boxes,
set(textbox1, 'String', num2str(Xmtkaki));
set(textbox2, 'String', num2str(Ymtkaki));

댓글 수: 5

how to know pixel value on that coordinate ?
You make up values depending on where you want the boxes to be positioned in the figure.
If you know the centroid, you can simply get the gray level of the original image at that centroid (or weighted centroid) location. Just be aware that the centroid is (x,y), NOT (row, column) so you need to get the graylevel as
grayLevelAtCentroid = yourImage(centroidY, centroidX);
By the way, did you run my demo (linked in my comment in my answer)? It puts a text string at the location of the centroid of each blob, and marks each centroid and weighted centroid with a "+" symbol.
did u mean this sir ?
thisBlobsPixels = blobMeasurements(k).PixelIdxList;
No, PixelIdxList is the list of linear indexes of the pixels, whereas PixelList is their gray levels.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Image Analyst
Image Analyst 2013년 4월 12일

0 개 추천

You probably want to call impixelinfo() (in the Image Processing Toolbox). This will give live, updated x,y,gray level information to a text box on the screen (that you can position wherever you want).

댓글 수: 2

I mean sir, how to know pixel value from titikX and titikY [1] ?
I don't know what they represent. Perhaps you need to run my image segmentation tutorial http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862, where I find object and their centroids and label them on the image.

댓글을 달려면 로그인하십시오.

태그

아직 태그를 입력하지 않았습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by