Valid indices are restricted in parlor loop

1 visualizzazione (ultimi 30 giorni)
Mark Buckup
Mark Buckup il 14 Ott 2019
Risposto: Walter Roberson il 14 Ott 2019
Is anyone able to help me understand how to format my arrays so I don't receieve this error. The error arises when I try to fill portions of my "CD8_image" zeros array with values inside the parfor loop.
region_width = width_end - width_start + 1; %fence post
region_height = height_end - height_start + 1; %fence post
interval = 2000;
number_x_tiles = region_width/interval;
number_y_tiles = region_height/interval;
CD8_image = zeros(region_height, region_width);
parfor i=1:(number_x_tiles)
frame_x_start = width_start + interval*(i-1);
frame_x_end = width_start + interval*i - 1; %fence post
for j=1:(number_y_tiles)
frame_y_start = height_start + interval*(j-1);
frame_y_end = height_start + interval*j - 1; %fence post
I1 = imread('CD8.tif','PixelRegion',{[frame_y_start frame_y_end],[frame_x_start frame_x_end]});
contrast_I1 = histeq(I1); %increase contrast
R_I1 = contrast_I1(:,:,1);
B_I1 = contrast_I1(:,:,3);
mask1 = R_I1 > B_I1 & R_I1 <160 & B_I1 < 40; %mess with these for red
F = medfilt2(mask1); %filter 1 (noise1)
F1_I1 = wiener2(F,[3 3]); %filter 2 (noise2)
F2_I1 = medfilt2(F1_I1); %filter 3 (noise1, try2)
F3_I1 = bwareafilt(F2_I1,[200 5000000]); %filter 4 (size)
height_1 = interval*(j-1)+1;
height_2 = interval*j;
width_1 = interval*(i-1);
width_2 = interval*i;
CD8_image(height_1:height_2,width_1:width_2) = F3_I1;
end
frame_y_start = height_start + interval*(j-1);
frame_y_end = height_start + interval*j - 1; %fence post
I1 = imread('CD8.tif','PixelRegion',{[frame_y_start frame_y_end],[frame_x_start frame_x_end]});
contrast_I1 = histeq(I1); %increase contrast
R_I1 = contrast_I1(:,:,1);
B_I1 = contrast_I1(:,:,3);
mask1 = R_I1 > B_I1 & R_I1 <160 & B_I1 < 40; %mess with these for red
F = medfilt2(mask1); %filter 1 (noise1)
F1_I1 = wiener2(F,[3 3]); %filter 2 (noise2)
F2_I1 = medfilt2(F1_I1); %filter 3 (noise1, try2)
F3_I1 = bwareafilt(F2_I1,[200 5000000]); %filter 4 (size)
CD8_image((interval*(j-1))+1:interval*j,(interval*(i-1)+1):interval*i) = F3_I1;
end

Risposte (1)

Walter Roberson
Walter Roberson il 14 Ott 2019
You cannot do that. Output arrays must be indexed in very simple ways, never as a range computed from the loop variable.
You can reorder the output to be tile height by tile width by number of tiles and write into (:, :, tilenumber) and then after the loop permute and reshape as needed. Or you can reorder to tile height by tile width by number of y tiles by number of x tiles, and inside the x tile loop construct a temporary 3d variable with the third dimension ordered by y tile number, and then after the y loop, write the 3d array into (:,:,:, x tilenumber), and then after the parfor permute and reshape as needed.

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by