MATLAB Answers

how to assign imagesc to figure 1

조회 수: 29(최근 30일)
Eiman Rana
Eiman Rana 2021년 9월 19일 23:49
댓글: Walter Roberson 2021년 9월 20일 9:05
In this part you will write a program to perform a simple analysis of a random image. First, generate a random array of size 40x40 with each entry being either 0 or 1 and display it in Figure 1. Next, write a program segment that searches for single entries (value = 1) that have no neighbors (all 8 neighbors have values of 0) and records them in another array of the same size. Display the results visually in Figure 2. An example run is shown below: content of random matrix (left) and entries with no neighbors (right).
Please help me with underlined part
n = 40;
m = 40;
A1 = rand(n,m) < 0.5;
imagesc(A1);

채택된 답변

Walter Roberson
Walter Roberson 2021년 9월 19일 23:52
fig1 = figure(1);
ax1 = axes('Parent', fig1);
imagesc(A1, 'Parent', ax1);
If there is an existing axes you want to draw into, then use its handle in the 'Parent' option of imagesc
  댓글 수: 1
Walter Roberson
Walter Roberson 2021년 9월 20일 2:06
I suggest you read about conv2() with regards to finding isolated pixels.

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

추가 답변(1개)

Image Analyst
Image Analyst 2021년 9월 20일 1:50
Following Walter's code call figure(2) to create a figure numbered "2", then use bwmorph() with the 'clean' option to remove single pixels. Use xor() with the original binary image to get an image with only the single, isolated pixels.
fig1 =
A1 =
imshow(A1)
output = bwmorph(
output = xor(
fig2 = figure(2);
imshow(output)
Complete this since it seems to be your homework and they probably don't want you to turn in our solution as your own. It should be trivial now that we've done most of it for you.
  댓글 수: 5
Walter Roberson
Walter Roberson 2021년 9월 20일 9:05
output = conv2(A1, [1 1 1;1 -1 1; 1 1 1], 'same') == -1;

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

Community Treasure Hunt

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

Start Hunting!

Translated by